开发者

Maybe a dumb question on timezones

开发者 https://www.devze.com 2022-12-16 01:00 出处:网络
I have confused myself to a point where I need to double check this with you all. Sorry if this is really a dumb question..

I have confused myself to a point where I need to double check this with you all. Sorry if this is really a dumb question..

Okay - I have a PHP web application running on Linux that needs to support timezones. I provide a calendar widget that allows the user to set their timezone then select the date and hours/minutes for some event.

I then store that value in a record as an int by using. When I need to show the date again to the user I just 开发者_如何学Pythonget their timezone setting and apply to the int value.

Code:

$dtzone = new DateTimeZone($time_zone);
$dtime = new DateTime($date_time, $dtzone);
$timestamp = $dtime->format('U');
return $timestamp;

Notes: $date_time comes in this format 'YYYY-MM-DD H:S' $time_zone is what they selected eg: America/Jamaica

Now I store the int returned in the database.

I then have a PHP script that I execute via CRON which runs within a server in Sydney - Australia.

My understanding is that all my script needs to do is get the servers current time stamp via time() then search the database for any integers with the exact same integer produced by the time() call. I don't have to worry about what timezone the user used to select the date/time.

Note that the CRON must run every minute as I allowed the user to select the minute as well.

Is this assumption correct?

Cheers

Marc


If you're storing the timestamps as int then you're most likely using unix timestamps which are always UTC. A unix timestamp is the same no matter where it is generated. Be it Jamaica, Sydney, or Mars.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号