dqy0707 2015-08-05 07:43
浏览 99

PHP Datetime ISO8601转换

I'm formatting a date in ISO8601 with Datetime and then i restore it, but restoring don't give me original value.

Test snippet

$d = new \DateTime('0000-00-00 00:00:00');
$formatted =  $d->format(\DateTime::ISO8601);
$restored  =  \DateTime::createFromFormat(\DateTime::ISO8601, $formatted);
var_dump($d);
var_dump($formatted);
var_dump($restored);

Result

object(DateTime)[5]
  public 'date' => string '-0001-11-30 00:00:00' (length=20)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Rome' (length=11)

string '-0001-11-30T00:00:00+0100' (length=25)


boolean false

PHP version PHP 5.4.28

  • 写回答

1条回答 默认 最新

  • dongyi9783 2015-08-05 07:53
    关注

    0th of Nulluary is not a date that exists. PHP does some time math with it (e.g. the 13th month becomes the 1st month of the following year, values <1 work the other way backwards), so you get what you get. There is no "right" answer for 0000-00-00, it's nonsense. It works fine with real dates.

    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测