dsuvs66406 2011-06-01 13:59
浏览 108
已采纳

在PHP 5.3中使用mktime()中的is_dst(不推荐使用参数)

From 5.3 the is_dst parameter is deprecated in mktime. But I need two previous time in timestamp, one of them with dst and the other without that.

E.g.: first time mktime("03","15","00","08","08","2008",1) and the other mktime("03","15","00","08","08","2008",0)

Can you help me to solve that problem?

  • 写回答

2条回答 默认 最新

  • dstm2014 2011-06-01 14:33
    关注

    Not a full answer, just some ideas I could think of... The DateTime::format() method accepts a format code that tells whether DST is on effect:

    $now = new DateTime;
    $is_dst = $now->format('I')==1;
    

    Now, in order to know what time it'd be if DST was the other way round, you have to find out when such change happens. This code:

    $time_zone = $now->getTimeZone();
    var_dump( $time_zone->getTransitions(strtotime('2011-01-01'), strtotime('2011-12-31')) );
    

    ... prints:

    array(3) {
      [0]=>
      array(5) {
        ["ts"]=>
        int(1293836400)
        ["time"]=>
        string(24) "2010-12-31T23:00:00+0000"
        ["offset"]=>
        int(3600)
        ["isdst"]=>
        bool(false)
        ["abbr"]=>
        string(3) "CET"
      }
      [1]=>
      array(5) {
        ["ts"]=>
        int(1301187600)
        ["time"]=>
        string(24) "2011-03-27T01:00:00+0000"
        ["offset"]=>
        int(7200)
        ["isdst"]=>
        bool(true)
        ["abbr"]=>
        string(4) "CEST"
      }
      [2]=>
      array(5) {
        ["ts"]=>
        int(1319936400)
        ["time"]=>
        string(24) "2011-10-30T01:00:00+0000"
        ["offset"]=>
        int(3600)
        ["isdst"]=>
        bool(false)
        ["abbr"]=>
        string(3) "CET"
      }
    }
    

    If you obtain the transitions for year the date belongs to, you can collect a list of offsets according for isdst TRUE and isdst FALSE. Once you pick an appropriate offset, the rest is easy:

    $winter_offset = 3600;
    $summer_offset = 7200;
    $difference = $winter_offset-$summer_offset;
    $winter = $now->modify( ($difference<0 ? '' : '+') . $difference . ' seconds');
    echo $winter->format('H:i:s');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝