Jump to content
Sign in to follow this  
terryds

How to adjust the time by the visitors' timezone

Recommended Posts

Hi..

How to adjust the time by visitors' timezone ?

I mean, by my timezone (GMT+4), I posted an article at 11:45 A.M.

And, I want my visitor see the time adjusted to his/her timezone.

 

For instance, if a man in GMT+2 see the time, it'll be 09:45 A.M.

 

Thanks in advance

Share this post


Link to post
Share on other sites

Do you want to assume their computer has the correct local time?

Share this post


Link to post
Share on other sites

Do you want to assume their computer has the correct local time?

Yes, i do.

 

So, the illustration is below.

I posted an article in my site. The timezone set in the configuration setting is GMT+4 (assume the time is 11:45 A.M.)

Then, I want my site visitors in other timezone see that the time i posted the article is adapted by their timezone ( If the man is in GMT+2 timezone, so he will see that the time i posted the article is 9:45 A.M.)

 

Please tell me how to do that

 

Sorry for my bad English skill

Edited by terryds

Share this post


Link to post
Share on other sites

In Php you can use...

$timestamp = 1000*Time(); //milliseconds from Jan 1, 1970

In Javascript you can use...

var timestamp = new Date().getTime(); //milliseconds from Jan 1, 1970

...so perhaps in Javascript you could create a millisecond offset global...

var msec_offset = Math.round(('<?php echo Time(); ?>' - Math.round(new Date().getTime()/1000))/3600)*3600*1000;

...then you could use the fact that Javascript can create a new date from a timestamp...

var date1 = new Date(millisecond_timestamp_from_Php + msec_offset);
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...