当前一周的 PHP 工作日,为什么 date() 和 strtotime 下周需要?

标签 php date strtotime

我正在使用以下代码获取工作日的 Y-m-d 格式:

$monday = date('Y-m-d', strtotime('Monday'));
$tuesday = date('Y-m-d', strtotime('Tuesday'));
$wednesday = date('Y-m-d', strtotime('Wednesday'));
$thursday = date('Y-m-d', strtotime('Thursday'));
$friday = date('Y-m-d', strtotime('Friday'));

今天是 2012-08-01(第 31 周),我需要的星期一值应该是 2012-07-30。

strtotime('Monday') 怎么会变成下周一?

最佳答案

因为 date('Y-m-d') 返回今天的日期,即八月。您正在将 monday 转换为 time。现在时间以 date(Y-m-d)(2012 年 8 月)表示。所以显而易见的答案是从今天开始的下一个星期一。

所以要得到上周的日期,使用

$monday=date(Y-m-d,strtotime('monday this week'))

关于当前一周的 PHP 工作日,为什么 date() 和 strtotime 下周需要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756351/

相关文章:

javascript - 是否有一个 JS 替代 Date.now() 不会根据时区变化?

php - Paypal 日期格式混淆了 strtotime()。我能做些什么?

php strtotime() 关闭 1 分钟?

php - 安全性 - Ajax 和 Nonce 使用

php - PDO 语句的参数编号无效

python - 将日期从字符串格式转换为 OLE 自动化日期

mysql - 需要在多列表中获取第一个日期

php - 获取上个月的日期范围

php - 以编程方式设置网页的默认缩放?

php - 使用正则表达式在 php 中过滤一些波斯语单词