php 获取某年母亲节日期
以下是在 PHP 中获取某年母亲节日期的代码:
function getMothersDay($year) {
// 母亲节是每年的5月第二个星期日
$date = new DateTime($year . '-05-01');
$week = $date->format('w');
if ($week == 0) {
$date->modify('+7 days');
} else {
$date->modify('+'.(7-$week).' days');
}
return $date->format('Y-m-d');
}
// 使用示例:
echo getMothersDay(2021); // 输出:2021-05-09
原文地址: https://www.cveoy.top/t/topic/e6ca 著作权归作者所有。请勿转载和采集!