Date & time question
I have set date and time variables by using:
$date = date("Y-m-d");
$time = date("H:i:s");
This will give me the date and time according the system time on my server, which uses Eastern Daylight Time.
However, I want to display the date and time on my web page showing Pacific Daylight Time. In other words, I want to show a date and time that is 3 hours less than the time returned by the statement above.
How can I modify my statements above to return the date and time minus 3 hours?
Use date('H:i:s', time() - 3*60*60);
time() returns the current unix timestamp in seconds, and subtracting 3*60*60 is the equivalent of knocking the clock back by three hours.
If that doesn't work use date('H:i:s', time() + 3*60*60);
(I can never be bothered to figure out if I should add or subtract the seconds, but trial and error sorts that out :))
Your first option was the one I needed. It worked just the way I wanted.
While it does the same thing, it may be easier to manage using mktime()
Which basically does what Skunk's code does but using mktime() you can subtract 3 hours. mktime() takes 5 optional args, starting with hour, minute, second, month,day,year if any are left out on the right it takes the current values of each one. So that example would produce the same result as
$time = date("H:i:s", mktime(date("H") - 3));
$time = date("H:i:s", mktime(date("H") - 3, date("i"), date("m"), date("d"), date("Y"));