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.

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

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大