当前一周的PHP工作日,为什么下周要使用date()和strtotime? [英] PHP weekdays of current week, why is date() and strtotime taking next week?

查看:96
本文介绍了当前一周的PHP工作日,为什么下周要使用date()和strtotime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取工作日的Ymd格式:

I am using the following code to get a Y-m-d format of weekdays:

$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。

Today is 2012-08-01 (week 31) the Monday value I need should be 2012-07-30.

strtotime('Monday')怎么会在下周一出现?

How come strtotime('Monday') makes it next monday?

推荐答案

因为 date('Ym-d')返回今天的日期,即8月。您将星期一转换为时间。现在,时间用 date(Ymd)(2012年8月)表示。因此,显而易见的答案是从今天开始的下一个星期一。

Because date('Y-m-d') returns today's date i.e.., month of august. And you are converting monday to time. now that time is represented in terms of date(Y-m-d) (august of 2012).. So the obvious answer would be the next coming monday starting from today.

要获取上周的日期,请使用

So to get last week's date,use

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

这篇关于当前一周的PHP工作日,为什么下周要使用date()和strtotime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆