Php 32-bit date parsing before 13Dec 1901

I happily used strtotime () on my development machine to parse dates, some of which date back to the 1800s, with an extreme example in the 1500s.

But my development machine is 64 bits and the server is 32 bits. On a 32-bit machine, any date before Fri, December 13, 1901 20:45:54 UTC is out of the acceptable range (see strtotime Notes).

I am happy to write some kind of user code for it, but I thought that I would ask if any of the built-in php functions could handle it. Dates are in ISO 8601 format.

What is centos 5.4 server with php 5.2.10?

+3
source share
1 answer

1901-12-12T05: 00: 00Z e.g.

I cannot verify this right now, but the DateTime constructor can accept your format without the need for createFromFormat . I can not say from the documentation.

Try

 try { $date = new DateTime('1901-12-12T05:00:00Z'); } catch (Exception $e) { echo "Arggh! ".$e->getMessage(); die(); } echo $date->format('Ymd H:i:s'); 

and see what happens, paying particular attention to whether he understands Z correctly (i.e. makes it UTC time).

DateTime uses 64-bit numbers inside any system and has no range limits.

As said, starting with 5.3, you can use createFromFormat , which can parse any date expressed by one of the date() placeholders. This is the best way, because you force it to analyze a specific pattern, rather than guessing it.

+3
source

All Articles