时区偏移功能在夏令时增加了1小时

时间:2016-05-11 09:33:49

标签: php timezone

这个时区偏移功能在夏天增加了一个小时。它适用于冬季。

任何人都可以看到错误:

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)));
}

1 个答案:

答案 0 :(得分:0)

这是法国时间的一个例子:

//[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;

OR

$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);