例如:
我正在尝试获取这些日期,这样我就可以在我的日历上标记它,而无需手动将未来几年的所有内容都放入.
I am trying to get these dates, so that I can mark it on my calendar without manually putting everything for the years to come.
修改答案!!
$curYir = date("Y");//current year
$MLK = date('Y-m-d', strtotime("january $curYir third monday")); //marthin luthor king day
$PD = date('Y-m-d', strtotime("february $curYir third monday")); //presidents day
$Est = date('Y-m-d', easter_date($curYir))); // easter
$MDay = date('Y-m-d', strtotime("may $curYir first monday")); // memorial day
//("may $curYir last monday") will give you the last monday of may 1967
//much better to determine it by a loop
$eMDay = explode("-",$MDay);
$year = $eMDay[0];
$month = $eMDay[1];
$day = $eMDay[2];
while($day <= 31){
$day = $day + 7;
}
if($day > 31)
$day = $day - 7;
$MDay = $year.'-'.$month.'-'.$day;
$LD = date('Y-m-d', strtotime("september $curYir first monday")); //labor day
$CD = date('Y-m-d', strtotime("october $curYir third monday")); //columbus day
$TH = date('Y-m-d', strtotime("november $curYir first thursday")); // thanks giving
//("november $curYir last thursday") will give you the last thursday of november 1967
//much better to determine it by a loop
$eTH = explode("-",$TH);
$year = $eTH[0];
$month = $eTH[1];
$day = $eTH[2];
while($day <= 30){
$day = $day + 7;
}
if($day > 30)
//watch out for the days in the month November only have 30
$day = $day - 7;
$TH = $year.'-'.$month.'-'.$day;
你可以利用php的这个功能.strtotime
You can leverage this function of php. strtotime
$currentYear = date("Y");
MLK 日 -
echo date('Y-m-d', strtotime("third monday of january $currentYear"));
总统日 -
echo date('Y-m-d', strtotime("third monday/OD February $currentYear"));
复活节 -
echo date('Y-m-d', strtotime("last sunday of march $currentYear"));
阵亡将士纪念日 -
echo date('Y-m-d', strtotime("last monday of may $currentYear"));
这篇关于如何使用php获取假期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!