因此,为了创建日历,我想要确定任何给定月份的第一个工作日是什么.我有以下代码:
$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'])) {
这样,您总是分配当前时间(),这就是为什么月份的第一天始终是当前月份的原因.
http://phpfiddle.org/main/code/4ja-928
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。