Etc/GMT+(offset) only providing GMT in PHP
According to PHP, the timezone in the format Etc/GMT+(offset)
is a valid timezone. Based on that, I would have assumes that this code would output a series of different timezomes:
$start_date = 'Dec 16, 2011';
$start_time = '09:45:00';
#$utime_zone = 'GMT'; <-- switching to GMT works!
$utime_zone = 'Etc/GMT';
for($i = -12; $i <= 12; $i++){
$curr = ($i >= 0)?'+'.$i: $i;
$str = ($start_date . " " . $sta开发者_Go百科rt_time . " " . $utime_zone.$curr);
echo $str . ' = ' . strtotime($str).PHP_EOL;
}
Unfortunately, the strtotime calls are all ignoring the timezone completely.
The output:
Dec 16, 2011 09:45:00 Etc/GMT-12 = 1324028700
Dec 16, 2011 09:45:00 Etc/GMT-11 = 1324028700
Dec 16, 2011 09:45:00 Etc/GMT-10 = 1324028700
...you get the idea.
Clearly I have made some assumption about this, but is there an easy way to convert from Etc/GMT+(offset)
to a GMT timestamp?
I don't know why is your case not working (apart form the big PHP warning saying not to use that method), but you could easily work around it using ISO-8601 date formatting
The format is basically Y-m-d\TH:i:s
and then either Z
for UTC or +/-hh:mm
.
$datetime = '2011-06-20T18:49:00';
echo $datetime.'+01:00 => '.strtotime($datetime.'+01:00')."<br />";
echo $datetime.'+03:00 => '.strtotime($datetime.'+03:00')."<br />";
gives you
2011-06-20T18:49:00+01:00 => 1308592140
2011-06-20T18:49:00+03:00 => 1308584940
精彩评论