drpogkqqi536984960 2014-05-15 20:02
浏览 105

PHP,日期偏移1天。 从DOY(Y-z)格式转换为字符串/ unix

I'm required to take a date in the format 'Y-z' which is year-doy (e.g, 2013-146) and convert that into a unix time stamp to be store into a database.

The issue i have is that i input 2013-146 and turn it into a DateTime Object. then when i output this date in unix or 'Y-m-d' format i get 2013-5-27 not 2013-5-26 which is the correct day.

You can verify the DOY on this NASA website and this NOAA website.

Summary: --I have the date: '2013-146' --Using DateTime::createFromFormat and echoing using 'Y-m-d' and 'Y-z' i get: 2013-5-27 and 2013-146 respectively. --This does not agree with the NASA website I listed and is offset by one day can anyone verify that I'm not losing my mind?

Here is the code you can test:

$year = 2013;  //where this outputs a simple year 'CCYY'
$day = 146;        //where this provides the day of year

$format = 'Y-z';    //specifying what format i'm creating the datetime with
$date = $year.'-'.$day;         //formatting the strings to the above $format
$timezone = new DateTimeZone('America/Chicago');     //specify the timezone
$fileDateStore = DateTime::createFromFormat($format, $date, $timezone);//, $timezone);  //create the DateTime object
$fileDateString = date_format($fileDateStore,"Y-m-d");  //format it so strtotime() can read it
$fileDate = strtotime($fileDateString);  //finally create the Unix Timestamp for the date.
$newfileDOY = date_format($fileDateStore,"Y-z");
echo 'newfileDOY = '.$newfileDOY.', ';
echo 'date = '.$date.', ';
echo 'fileDateString = '.$fileDateString.', ';
echo 'fileDate = '.$fileDate.PHP_EOL;
  • 写回答



      相关推荐 更多相似问题


      • ¥15 使用DWY100k数据集对UEA进行测试,出现报错:IndexError: index 125000 is out of bounds for axis 0 with size 95500
      • ¥15 前端vue实现根据图片url生成pdf文件
      • ¥15 RfidReader资源Q个
      • ¥20 user-agent是否是唯一的,有没有可能相同
      • ¥15 关于#开会#的问题,如何解决?(语言-c++)
      • ¥15 关于#二十四点问题#的问题
      • ¥15 运行kitex的demon出错(求大家解决)
      • ¥15 开发一个类似 typora 这样的软件需要多少钱?
      • ¥15 clearcase7.0安装包
      • ¥15 断点回归模型月度核密度检验不连续