PHP-获取一年中的上周编号 [英] PHP - get last week number in year
本文介绍了PHP-获取一年中的上周编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我一年中的最后几周?
Tell me please how to get the last number of weeks in a year?
推荐答案
function getIsoWeeksInYear($year) {
$date = new DateTime;
$date->setISODate($year, 53);
return ($date->format("W") === "53" ? 53 : 52);
}
o
日期格式给出了 ISO-8601年号.我们可以使用它,并且无效"日期会自动转为有效日期(2011-02-31
给出2011-03-03
)这一事实,以确定给定的一年是否有53周.如果没有,则必须为52.
The o
date format gives the ISO-8601 year number. We can use this, and the fact that "invalid" dates are automatically rolled around to make valid ones (2011-02-31
gives 2011-03-03
), to determine if a given year has 53 weeks. If does not, then it must have 52.