對不起,如果這是重複的。爲什麼下面的代碼錯誤呢?目前,它返回12月6日,12月第一個星期五(8詢問2013年10月)爲什麼下面的代碼會在11月份的第二個星期五返回,但在12月份的第一個星期五?
$thisMonth = date('m');
$year = date("Y");
$thismonthName = date("M.", mktime(0, 0, 0, $thisMonth,0,$year));
if ($thisMonth < 12) {
$nextmonthName = date("M.", mktime(0, 0, 0, $nextMonth,1,$year));
} else {
$nextMonth = 1;
$nextmonthName = date("M.", mktime(0, 0, 0, $nextMonth,1,$nextYear));
}
$thisDate = date('M j', strtotime($nextmonthName . $year . "first friday"));
print ("second friday next month is " . $thisDate);
但修改它只是下個月是,像這樣,
$thisMonth = date('m');
$year = date("Y");
$thismonthName = date("M.", mktime(0, 0, 0, $thisMonth,0,$year));
if ($thisMonth < 12) {
$nextmonthName = date("M.", mktime(0, 0, 0, $nextMonth,0,$year));
} else {
$nextMonth = 1;
$nextmonthName = date("M.", mktime(0, 0, 0, $nextMonth,0,$nextYear));
}
$thisDate = date('M j', strtotime($nextmonthName . $year . "first friday"));
print ("second friday next month is " . $thisDate);
返回11月8日,第二11月的星期五。這是爲什麼?
您在第一個星期五字符串中缺少空格,所以您實際上正在製作'Mmm 2013第一個星期五',再加上'$ nextmonth'似乎從未在任何地方定義過。 –
哎呀。重新定義了$ nextmonth並修復了這個空間,但仍然沒有在11月份正確返回。這似乎是由於11月開始於星期五 – user2864757
'echo date_create('nextth month of the month') - > format('Ym-d');' –