简体   繁体   中英

Timezones, daylight saving etc

We have a site that currently runs auctions at a certain time (picked by user) this was all working fine, as when the server hit that time the auction would start. We then had to add timezones, dependant on where the user lived. This would then add or take away a certain amount of hours depending on the drop-down selected, we again had this working fine, but then everything when potty when the clocks went forward, took me a while to work out that daylight saving now managed to break everything.

I know there is a solution to this problem as many people must have come across it, but I can't seem o work it out.

Our server currently runs UTC.

Any help on this would be great...

I'm not 100% on this, but I would say that provided your timezone database (part of your linux system) is up-to-date then you should be able to do this:

<?php
$currentTimezone = date_default_timezone_get();
date_default_timezone_set($usersTimezone);
echo date('j F Y G:i:s'); // Time shown in user's timezone, DST accounted for
date_default_timezone_set($currentTimezone);
?>

If you look through PHP's date functions there are probably less twisty ways to do this. I'm just not very clued up on those functions ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM