douyin2435 2013-04-23 16:10
浏览 24
已采纳

PHP似乎正在返回不正确的工作日

First of all, here is my code:

<?php
$year = 1006;
while ($year <= 1996)
{
    $date = '1/26/' . $year;
    if (date('l', strtotime($date)) == 'Monday')
    {
        echo $date . PHP_EOL;
    }

    $year += 10;
}
?>

This is supposed to output the January 26s between 1000 and 1999 where the year ends with a 6 and the date falls on a Monday. Here is the output:

1/26/1006
1/26/1096
1/26/1136
1/26/1186
1/26/1226
1/26/1316
1/26/1366
1/26/1406
1/26/1496
1/26/1536
1/26/1586
1/26/1626
1/26/1756
1/26/1846
1/26/1976

All seems well. However, when I look at few of these years on timeanddate.com, the weekdays do not seem to have anything in common:

1/26/1006 falls on a Saturday

1/26/1406 falls on a Tuesday

1/26/1756 does fall on a Monday

What's going on here?

  • 写回答

1条回答 默认 最新

  • dpnfjx755573 2013-04-23 16:19
    关注

    strtotime() converts a string representation of a date into a unix timestamp - the number of seconds since jan 1, 1970. You may start to see the problem here...

    A timestamp is typically stored in a 32 bit integer, which gives a range between 1970 and 2038. Trying to generate timestamps for dates outside that range will give you undefined behavior.

    -- edit --

    From the php manual:

    The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1