问题
My understanding is that datetimes in php are represented as the number of milliseconds after a certain date (some time in 1960 I think?). How to I construct a datetime that represents the earliest allowable date in php? An example possible syntax would be:
$date = new DateTime(0);
but this doesn't work. Is there some other way to do this?
Thanks for any input.
回答1:
You're pretty close
$date = (new DateTime())->setTimestamp(0);
Will give January 1st, 1970
回答2:
echo date('d-m-Y', 0); // outputs: 01-01-1970
epoch 0
gives the unix timestamp 01-01-1970
or 00:00:00 UTC on January 1st 1970.
来源:https://stackoverflow.com/questions/40095859/how-do-i-get-the-earliest-possible-datetime-in-php