terryds Posted July 7, 2014 Share Posted July 7, 2014 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 Link to comment Share on other sites More sharing options...
davej Posted July 7, 2014 Share Posted July 7, 2014 Do you want to assume their computer has the correct local time? Link to comment Share on other sites More sharing options...
terryds Posted July 7, 2014 Author Share Posted July 7, 2014 (edited) 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 July 7, 2014 by terryds Link to comment Share on other sites More sharing options...
davej Posted July 7, 2014 Share Posted July 7, 2014 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); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now