Home >
Article > Backend Development > HP implementation calculates the number of weeks in a year and returns the start time and end time of a week (optional return timestamp or date)
HP implementation calculates the number of weeks in a year and returns the start time and end time of a week (optional return timestamp or date)
WBOYOriginal
2016-07-25 08:45:311039browse
function getWeekStartAndEnd ($year,$week=1) {
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set("Asia/Shanghai");
$year = (int)$year;
$week = (int)$week;
//Calculate the total number of weeks in this year based on the given year
$date = new DateTime;
$date->setISODate($year, 53);
$weeks = max($date->format("W"),52);
//If the given week number is greater than the total number of weeks or less than or equal to 0
if($week>$weeks || $week< =0){
return false;
}
//If the number of weeks is less than 10
if($week<10){
$week = '0'.$week;
}
//The start and end timestamps of the current week
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn