Question

I have a PHP script that's called by an external vendor. One of the GET values is a timestamp that is MySQL format, GMT + 0200. Here's an example:

2012-07-16 16:51:22

I can convert that into the format I'm after using:

$converted =  date ("m/d/Y h:i:s A", strtotime ($ts) ); 

However I would also like to convert it to the local time, e.g. GMT + 10. I'm stumped on this last bit - appreciate if anyone can recommend some options for converting between timezones/GMT offsets as I'm not sure which PHP function to use.

Was it helpful?

Solution

Use DateTime, like so:

$date = new DateTime($ts);
$date->setTimeZone(new DateTimeZone("Europe/Amsterdam");
$converted = date_format($date, 'm/d/Y h:i:s A');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top