Whats the best way to adjust times to acount for daylight saving. Is there any built in functions or do I have to manually work it out?
Printable View
Whats the best way to adjust times to acount for daylight saving. Is there any built in functions or do I have to manually work it out?
Usually the operating system takes care of this. However, you can use both the date() and localtime() functions to find otu whether or not daylight savings time is in effect.
Problem is though the server is if the server is in the US and the time I'm after is british time then the server won't adjust for daylight saving at the right time. :(
i dont beleive there is a way to ask the client for the time. if they stated that they were (lets say) 4 hours difference, you could eassily do it:
http://us3.php.net/localtime (there are examples in there)
No if I use localtime() it will adjust for daylight savings based on when the US implement it, because thats where the server is. I guess I'll just have to put up with that as I expect most my customers will have UK based servers, even though my demo server is US based :(.Quote:
Originally Posted by ALL
Like the forum software, you could ask the user to specify their timezone offset and ask them whether they have daylight savings time in their country. You can also use gmdate() function to return the GMT time which will be calculated using the servers timezone offset.
You can also use the date function to find the offsaet from GMT in seconds. Combined with the offset for the current locale (e.g GMT+2hours) you can calculate the timestamp for the client based on that:
PHP Code:$server_gmtoffset = (int) date('Z');
$local_offset = 2; //in hours
$localtime = time() - $server_gmtoffset - ($local_offset * 60 * 60);
Use setlocale() and hope the locale is installed on the target server:
PHP Code:<?php
setlocale("de-AT"); // Set locale to German, Austria