strtotime( "wed year-month +2 Weeks")を使用してphpで第3水曜日を取得できますか、それとも次のような複雑なコードが必要ですか:http ://www.danielkassner.com/2010/05/22/get-date位置ごと、つまり1月の第3水曜日?
質問する
389 次
1 に答える
1
これを試して:-
/**
* int nth_day_of_month(int $nbr, str $day, int $mon, int $year)
* $nbr = nth weekday to find
* $day = full name of weekday, e.g. "Saturday"
* $mon = month 1 - 12
* $year = year 1970, 2007, etc.
* returns UNIX time
*/
function nth_day_of_month($nbr, $day, $mon, $year)
{
$date = mktime(0, 0, 0, $mon, 0, $year);
if($date == 0)
{
user_error(__FUNCTION__."(): Invalid month or year", E_USER_WARNING);
return(FALSE);
}
$day = ucfirst(strtolower($day));
if(!in_array($day, array('Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday')))
{
user_error(__FUNCTION__."(): Invalid day", E_USER_WARNING);
return(FALSE);
}
for($week = 1; $week <= $nbr; $week++)
{
$date = strtotime("next $day", $date);
}
return($date);
}
$d = nth_day_of_month($week_no,$curr_week_day, $fmonth, $fyear);
echo date('d-m-Y',$d)."<br />";
于 2012-09-19T13:53:36.397 に答える