编辑:此功能确实在PHP中工作,它在CakePHP框架内并不适用于我,因为我原本在发布时没有考虑到这一点。将格林尼治标准时间转换为当地时间
此函数采用字符串格式化日期/时间和本地时区(例如'America/New_York')。它应该将时间转换回当地时区。目前,它不会改变。
我传的那样:“2011-01-16 4时57分00秒”,“美国/纽约”和我回去,同时我通过在
function getLocalfromGMT($datetime_gmt, $local_timezone){
$ts_gmt = strtotime($datetime_gmt.' GMT');
$tz = getenv('TZ');
// next two lines seem to do no conversion
putenv("TZ=$local_timezone");
$ret = date('Y-m-j H:i:s',$ts_gmt);
putenv("TZ=$tz");
return $ret;
}
我见过的引用。到default_timezone_get/set的新方法。我目前没有兴趣使用该方法,因为我希望此代码能够与旧版本的PHP一起工作。