gpt4 book ai didi

php - 有人可以在 PHP strtotime 中解释这种奇怪的行为吗

转载 作者:行者123 更新时间:2023-12-05 02:11:08 26 4
gpt4 key购买 nike

我正在开发一个日历函数,它应该输出周的名称和我有周数和年份的日期

代码在 2018 年时运行良好,但一到 2019 年,就出问题了

echo date("Y-m-d D", strtotime("monday 2018W37")); // outputs 2018-09-10 Mon
echo date("Y-m-d D", strtotime("monday 2019W37")); // outputs 2019-09-15 Sun

但是如果您查看有效日历,2019 年第 37 周的星期一理所当然是星期一,日期是 2019-09-09

有人可以解释这种行为并提供 strtotime 的替代方法吗。

最佳答案

你应该这样写,

echo date("Y-m-d D", strtotime("2018W37")) . "\n"; // outputs 2018-09-10 Mon
echo date("Y-m-d D", strtotime("2019W37")) . "\n"; // outputs 2019-09-9 Mon

echo date("Y-m-d D", strtotime("2018W37-1")) . "\n"; // outputs 2018-09-10 Mon
echo date("Y-m-d D", strtotime("2019W37-1")) . "\n"; // outputs 2019-09-9 Mon

关于php - 有人可以在 PHP strtotime 中解释这种奇怪的行为吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57889801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com