因此,为了创建日历,我想要确定任何给定月份的第一个工作日是什么.我有以下代码:
$today=date('Y-m-d');
IF (!$_GET) {
$Now=time();
}
ELSE {
$Now=strtotime($_GET['month']);
}
// the month in question is linked through a GET form variable in the Ymd format
$thisdayNow=date('Y-m-d', $Now);
$monthyear=date('F Y', $Now);
$thismonth=date('M', $Now);
$thisyear=date('Y', $Now);
$weekday=date('l', $Now);
$firstday = new DateTime($thisdayNow);
$firstday->modify('first day of this month');
$work=$firstday->format('Ymd');
$firstweekday=date('l', $work);
$firstdayweek=date('w', $work);
ECHO 'Today is '.$thisdayNow.'<br />';
ECHO 'The first day of the month was '.$work.'<br />';
ECHO 'Today is a '.$weekday.'.<br />';
ECHO 'The first day of this month was a '.$firstweekday.', the '.$firstdayweek.'th day of the week.<br />';
这会返回:
Today is 2013-05-06
The first day of the month was 20130501
Today is a Monday.
The first day of this month was a Saturday, the 6th day of the week.
There are 31 days this month.
对我所做错的任何帮助都将不胜感激!!!
解决方法:
$inputMonth = '2013-05-01';
$month = date("m" , strtotime($inputMonth));
$year = date("Y" , strtotime($inputMonth));
$getdate = getdate(mktime(null, null, null, $month, 1, $year));
echo $getdate["weekday"];
生产:
星期三
如果问题仍然存在.
问题可能在这里:
IF (!$_GET) {
应该
if (!isset($_GET['month'])) {
这样,您总是分配当前时间(),这就是为什么月份的第一天始终是当前月份的原因.