tags:

views:

34

answers:

1

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

+1  A: 

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 ;)

d11wtq
It actually looks like you can just create an instance of DateTimeZone and ask for the offset. This should take DST into account, I would imagine. That's basically the job of your timezone database to maintain all that stuff.
d11wtq
I can confirm that this works. I just tested it by asking for the time at Europe/London which is currently in DST. I'm in Australia/Melbourne and we're not in DST. The script correctly output the time at London right now.
d11wtq
I have been working with the date_default_timezone_set and its pretty much there, just one final hurdle to get over, and where the data is an hour out when sent to flash... but thats a whole new question!
jimbo