php 星期几到天数(星期一 = 1,星期二 = 2)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4961793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
day of the week to day number (Monday = 1, Tuesday = 2)
提问by zmol
Does php have a function to automatically convert dates to their day value, where Monday=1, Tuesday=2, etc. Something like this
php 是否具有自动将日期转换为其日期值的功能,其中星期一 = 1,星期二 = 2,等等。类似这样的
$daynum = func('wednesday'); //echos 3
回答by ceejayoz
$day_of_week = date('N', strtotime('Monday'));
回答by Damien Pirsy
回答by adrianbanks
The datefunction can return this if you specify the format correctly:
该日期函数可以返回这个,如果你正确地指定格式:
$daynum = date("w", strtotime("wednesday"));
will return 0 for Sunday through to 6 for Saturday.
将在周日返回 0 到周六返回 6。
An alternative format is:
另一种格式是:
$daynum = date("N", strtotime("wednesday"));
which will return 1 for Monday through to 7 for Sunday (this is the ISO-8601 represensation).
它将从星期一返回 1 到星期日返回 7(这是 ISO-8601 表示)。
回答by Wige
$day_number = date('N', $date);
This will return a 1 for Monday to 7 for Sunday, for the date that is stored in $date. Omitting the second argument will cause date() to return the number for the current day.
对于存储在 $date 中的日期,这将返回星期一的 1 到星期日的 7。省略第二个参数将导致 date() 返回当天的数字。