如何获取当月第一天的名称(~星期一)?或者仅仅是值(monaday=0,tuesday=1 ...)在PHP中?
我有$date = getdate(),我试着做一个日历,但我需要知道日历中第一天的偏移量。
编辑:已修复问题:我只询问第1天。
发布于 2012-03-07 19:14:40
这将为您提供三个字母,从本月的第一天开始
echo date('D',mktime(0, 0, 0, date('m'), 1));以数字表示
echo date('N',mktime(0, 0, 0, date('m'), 1));发布于 2012-03-07 19:11:38
有关可用于处理日期的格式的列表,请参阅。在本例中,您将需要"l":
$day = date("l"); //$day will be the full name of the current day更新:
要获取当月第一天的名称,请将当前日期作为第二个参数传递:
$day = date("l", mktime(0, 0, 0, date("m"), 1, date("Y")));
//date("m") is the numeric representation of the current month
//date("Y") is the four-digit representation of the current year
//$day will be the name of the day of the first of march of this year (thursday normally :D)发布于 2012-03-07 19:40:21
足够有趣了,所以我为你写了代码。:-)
<?php
$month=date('m');
$year=date('Y');
$first=$month.'/1/'.$year;
$first=strtotime($first);
$weekday1=date('D',$first); //or $weekday1=date('l',$first);
echo $weekday1;
?>在注释中,'l‘是一个小写的"L“。
https://stackoverflow.com/questions/9600335
复制相似问题