开发者

Unix timestamp before 1970 (even before 1700), using PHP

how can i work with dates before 01.01.1970?

i need to get first day of the month for dates fro开发者_开发百科m year 1700.

how can i achieve that?

thank you in advance!


You can use DateTime.

Example:

<?php
$d = new DateTime("1780-06-01");
echo $d->format("l"); //Thursday

You should, however, consider that the Gregorian Calendar was adopted in different instants throughout the world.


Try using the Zend Date classes, or the older PEAR Date class


If the year is <1970 or the value is negative, the relationship is undefined.

-- The Open Group, Single Unix Specification, Base definitions (4: General concepts)

As you can see, it's not defined how Unix timestamps before 1970 would map to dates. It is only defined for later dates.

If you want to go to dates before 1970, you need to always work with actual dates, like ISO dates (2008-12-31T23:59:59). You can use DateTime class to represent any date you can think of but ever created it from a Unix timestamp or convert it to a Unix timestamp if the year is before 1970 as that will simply yield undefined results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜