我尝试使用date函数在PHP中获取当前月份的第一个月,然而,即使我手动更改日期字符串,输出也不完全是我想要的。
//get Current date
$dat=date("Y-m-d H:i:s");
//date with same month and year but first day of month in the above date
$d=date("Y-M-01",strtotime($dat));
//date with first day of month printed correctly
echo $d;
//day not printing correctly. First day is not printing.
echo date('N',$d);这是我得到的输出:
//This is output of date after setting first day of month
2013-Dec-01
//but when above printed date is used in as date('N',above Printed date)
//the result is 4 and not 1
4发布于 2013-12-26 20:37:25
发布于 2013-12-26 20:39:00
发布于 2013-12-26 20:40:55
首先,date函数希望第二个参数是一个时间戳,您给它一个字符串($d)。
其次,日期格式中的N是星期几的数字表示,而不是月份。你要找的是d。
https://stackoverflow.com/questions/20784933
复制相似问题