dongzhuan1185 2013-12-02 16:42
浏览 66
已采纳

Php Class对象DateTime转换为时间戳,然后又回到日期会产生10分钟的差异?

So I am working on some file code to reorder media files based on a range of dates but when parsing a date extracted from the file name I am running into this issue

    $filename = "G:\Video\Home\testfolder\1-01-2012\20120101031153.m2ts";
    $filebase =basename($filename);
          if(strlen(basename($fileBase,'.'.$info['extension']))==14){
                $fYear = substr($fileBase,0,4);
                $fMonth = substr($fileBase,4,2);
                $fDay = substr($fileBase,6,2);
                $fHour = substr($fileBase,8,2);
                $fMin = substr($fileBase,10,2);
                $fSec = substr($fileBase,12,2);
                $FNDateTime = new DateTime($fYear.'-'.$fMonth.'-'.$fDay.' '.$fHour.':'.$fMin.':'.$fSec);
                $FNDateTimeRe = date('d-m-Y H:m:s', $FNDateTime->getTimestamp());
                printf(' FileNameExtractedTime: '.$FNDateTimeRe);
}

here is the weird part the $FNDateTime object - holds the date "2012-01-01 03:11:53" as it should. however when I check the reversal just to ensure everything is good ... $FNDateTimeRe shows the value as "01-01-2012 03:01:53" as you can see its exactly 10 minutes less....

I checked my Timezones and I explicitly set

date_default_timezone_set('AUSTRALIA/Brisbane');

to ensure consistency but no dice !!

I am sure I am missing something glaringly obvious: any help appreciated.!

Development environment: Windows 7, apache 2.2.22 php 5.3.13...

  • 写回答

1条回答 默认 最新

  • douchun5976 2013-12-02 16:45
    关注

    m in the date format is not minutes, as you have used it for month already. Try i.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?