我可以在 php 中使用 strtotime 获得第三个星期三(“周三年月 +2 周”)还是我需要像这里这样的复杂代码:http ://www.danielkassner.com/2010/05/22/get-date -按职位,即一月第三个星期三?
问问题
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 回答