Jump to content

time differences


liamoco

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.