PHP - strtotime, specify timezone

This will work if for some reason you're using <5.2 (Heaven forbid).

$reset = date_default_timezone_get();
date_default_timezone_set('America/New_York');
$stamp = strtotime($dateStr);
date_default_timezone_set($reset);

But anything 5.2 and above, I'd strongly recommend you opt for @salathe's answer.


$date = new DateTime($dateStr, new DateTimeZone($timezone));

$timestamp = $date->format('U');


The accepted answer is great if you're running PHP > 5.2 (I think that's the version they added the DateTime class). If you want to support an older version, you don't want to type as much, or if you just prefer the functional approach there is another way which also does not modify global settings:

$dateStr = '2008-09-11 00:00:00';
$timezone = 'America/New_York';
$dtUtcDate = strtotime($dateStr. ' '. $timezone);

Tags:

Php

Timezone

Date