How do I get the earliest possible datetime in php?

本秂侑毒 提交于 2020-01-03 16:30:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!