这个时区偏移函数在夏天增加了一个小时。它在冬天工作。
有人能看到哪里出了问题吗:
public static function Date_GetOffset($order) {
$tz = new DateTimeZone("Europe/Copenhagen");
$date = new DateTime($order->order_datetime, $tz);
$trans = $tz->getTransitions();
foreach ($trans as $k => $t) {
if ($t["ts"] > $date->format('U')) {
$DST = $trans[$k-1]['isdst'];
break;
}
}
if (empty($DST)) {
$DST = 0;
}
$config = JFactory::getConfig();
$timezone = $config->get('offset');
//$tz=timezone_open("Europe/London");
$dateTimeGMT=date_create("now",timezone_open($timezone));
$offset = timezone_offset_get($tz,$dateTimeGMT);
$offset = $offset / 3600;
$offsetText = "+".(string)($DST + $offset)." hours";
return date("Y-m-d H:i:s", strtotime($offsetText, strtotime($order->order_datetime)));
}
这里是法国时间的一个例子:
//[Modif oto]Auto Manage of summer time
// Origine : $diff = ($pun_user['timezone'] + $pun_user['dst']) * 3600;
if($pun_user['timezone'] == 1) {// Timezone of France
date_default_timezone_set('Europe/Paris'); //Forcing timezone
if(date('I')) $diff = 7200; // Summer?
else $diff = 3600;
}
else $diff = ($pun_user['timezone'] + $pun_user['dst']) * 3600;
或
$date_default_save = date_default_timezone_get();
date_default_timezone_set($pun_user['timezone']);
if(date('I')) .... // User is in summer
....
date_default_timezone_set($date_default_save);