[英]How can I get the day of a specific date with PHP
我想得到 10 月 22 日的那一天(星期日、星期一……)。我该怎么做?
You can use the date
function. 您可以使用
date
功能。 I'm using strtotime
to get the timestamp to that day ; 我正在使用
strtotime
获取当天的时间戳; there are other solutions, like mktime
, for instance. 还有其他解决方案,例如
mktime
。
For instance, with the 'D' modifier, for the textual representation in three letters : 例如,使用“D”修饰符,对于三个字母的文本表示:
$timestamp = strtotime('2009-10-22');
$day = date('D', $timestamp);
var_dump($day);
You will get : 你会得到 :
string 'Thu' (length=3)
And with the 'l' modifier, for the full textual representation : 并使用'l'修饰符,用于全文表示:
$day = date('l', $timestamp);
var_dump($day);
You get : 你得到 :
string 'Thursday' (length=8)
Or the 'w' modifier, to get to number of the day (0 to 6, 0 being sunday, and 6 being saturday) : 或者'w'修饰符,以得到当天的数字(0到6,0表示星期日,6表示星期六) :
$day = date('w', $timestamp);
var_dump($day);
You'll obtain : 你会得到:
string '4' (length=1)
$date = '2014-02-25';
date('D', strtotime($date));
$datetime = DateTime::createFromFormat('Ymd', '20151102');
echo $datetime->format('D');
$date = '2009-10-22';
$sepparator = '-';
$parts = explode($sepparator, $date);
$dayForDate = date("l", mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]));
$date = strtotime('2016-2-3');
$date = date('l', $date);
var_dump($date)
(i added format 'l' so it will return full name of day) (我添加格式'l'所以它将返回日期的全名)
$timestamp = strtotime('2009-10-22');
$day = date('D', $timestamp);
var_dump($day);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.