liamoco Posted December 16, 2010 Share Posted December 16, 2010 I am making a php/ajax chat, when a post is sent to the chat, a timestamp using mktime() is stored in the database to show when that post was sent. My concern is that I am from England and my timestamp is GMT +0. Will people from different locations around the world see the wrong times that other users post into the chat? If so what do I need to do to make this work ideally? Thanks Link to comment https://forums.phpfreaks.com/topic/221904-time-differences/ Share on other sites More sharing options...
litebearer Posted December 16, 2010 Share Posted December 16, 2010 random thought, (sure there is a better way) presuming users are registered users... 1. store the time as GMT time 2. have field in db that holds the offset for a user from GMT 3. when user logs in, get his/her offset and use that combined with the stored GMT to display dates/times in users local time. ie user 1 in UK - offset 0 - when user 1 sees a record with 11AM as stored value he/she see 11AM; whereas a user in CA USA would have offset of -8 and as such would see same record as 3AM is that somewhat what you are seeking? Link to comment https://forums.phpfreaks.com/topic/221904-time-differences/#findComment-1148324 Share on other sites More sharing options...
liamoco Posted December 16, 2010 Author Share Posted December 16, 2010 Yes thank you litebearer, how to I get the offset value for a user? Link to comment https://forums.phpfreaks.com/topic/221904-time-differences/#findComment-1148326 Share on other sites More sharing options...
johnny86 Posted December 16, 2010 Share Posted December 16, 2010 What about using PHPs DateTime object with DateTimeZone object? <?php $timezone = new DateTimeZone("Europe/London"); $date = new DateTime(null, $timezone); // OR just $date = new DateTime(null, new DateTimeZone("Europe/London"); // Either way $date will now produce times according to given timezone ?> Read more: http://www.php.net/manual/en/class.datetime.php http://www.php.net/manual/en/class.datetimezone.php Link to comment https://forums.phpfreaks.com/topic/221904-time-differences/#findComment-1148335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.