我需要使用 php 代码每个月的第一个星期日日期。
请帮帮我。
getSunday();
这是获得每月第一个星期日的最佳方式
echo date("Y-m-d", strtotime("first Sunday of ".date('M')." ".date('Y').""));
您可以使用日期/时间扩展。
$start = new DateTime('2012-12-31');
$end = new DateTime('2013-12-31');
$interval = DateInterval::createFromDateString('first sunday of next month');
$period = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
foreach($period as $time) {
echo $time->format("F jS") . "<br>\n";
}
/*
January 6th
February 3rd
March 3rd
April 7th
May 5th
June 2nd
July 7th
August 4th
September 1st
October 6th
November 3rd
December 1st
*/
我正在寻找 DTS 日期,所以这是我找到它们的方法:
$dtsStart = date('Y-m-d 02:00:00', strtotime('Second Sunday Of March 2015'));
$dtsEnd = date('Y-m-d 02:00:00', strtotime('First Sunday Of November 2015'));
function firstSunday($DATE)
{
$date = strftime("%Y-%m",$DATE);
$day = trim(strftime("%e",$DATE));
for($day; $day <= '7'; $day++){
$dd = strftime("%A",strtotime($date.'-'.$day));
if($dd == 'Sunday'){
return strftime("%Y-%m-%d",strtotime($date.'-'.$day));
}
}
}