Question

I'm using strtotime to create a timestamp from some ropey XML, but the timezone is incorrect.

How can I remove 5 hours from the time?

Was it helpful?

Solution

If you know the timezone, you can set it with date_default_timezone_set()

When that's set, you can just do this in strtotime() as you know.

strtotime("-5 hours", $time);

OTHER TIPS

You probably want something like:

date('Y-m-d H:i:s', time() - 18000);

This formats a string as a date and time, for the current time in seconds since epoch - 18000 seconds (five hours). You can adjust the number you are subtracting to adjust how many hours you're adjusting by. It might be more clear if you write the 18000 as (60*60*5).

strtotime() can have unexpected consequences with strings where ordering is different than the US. European notation (01/02/2009) would be read as January 2nd where it is meant to be February 1st. This is the only issue I can see with olafur's solution, other than that it is solid, but either this one or that one will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top