PHP Datetime fail to convert negative ISO8601 date

后端 未结 1 1853
迷失自我
迷失自我 2021-02-10 08:53

Converting a negative date with DateTime get me false

Test code

var_dump(\\DateTime::createFromFormat(\\DateTime::ISO8601, \'-0001-11-30T00:00:00+0100\')         


        
相关标签:
1条回答
  • 2021-02-10 09:28

    According to manual of Format

     public string DateTime::format ( string $format )
    

    where

    $format
    
    Format accepted by date().
    

    and if you look in date()

    $d->format(\DateTime::ISO8601);
    

    should be

    $d->format("c")
    

    because "c" is according to format in date()

    ISO 8601 date (added in PHP 5)

    In my test $d->format(\DateTime::ISO8601); outputs

    2015-09-15T00:00:00+0200

    while

    $d->format("c");
    

    outputs

    2015-09-15T00:00:00+02:00

    I hope it helps.

    0 讨论(0)
提交回复
热议问题