PHP获取一年有几周以及每周开始日期和结束日期
2021-06-05 07:02
标签:form function amp time == 开始时间 code this char 代码一: 代码二: PHP获取一年有几周以及每周开始日期和结束日期 标签:form function amp time == 开始时间 code this char 原文地址:https://www.cnblogs.com/niuben/p/12335613.htmlphp
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set("Asia/Shanghai");
$year = (int)$_GET[‘year‘];
$week = (int)$_GET[‘week‘];
$weeks = date("W", mktime(0, 0, 0, 12, 28, $year));
echo $year . ‘年一共有‘ . $weeks . ‘周
‘;
if ($week > $weeks || $week )
{
$week = 1;
}
if ($week )
{
$week = ‘0‘ . $week;
}
$timestamp[‘start‘] = strtotime($year . ‘W‘ . $week);
$timestamp[‘end‘] = strtotime(‘+1 week -1 day‘, $timestamp[‘start‘]);
echo $year . ‘年第‘ . $week . ‘周开始时间戳:‘ . $timestamp[‘start‘] . ‘
‘;
echo $year . ‘年第‘ . $week . ‘周结束时间戳:‘ . $timestamp[‘end‘] . ‘
‘;
echo $year . ‘年第‘ . $week . ‘周开始日期:‘ . date("Y-m-d", $timestamp[‘start‘]) . ‘
‘;
echo $year . ‘年第‘ . $week . ‘周结束日期:‘ . date("Y-m-d", $timestamp[‘end‘]);
?>php
header("Content-type:text/html;charset=utf-8");
function getIsoWeeksInYear($year)
{
$date = new DateTime;
$date->setISODate($year, 53);
return ($date->format("W") === "53" ? 53 : 52);
}
function weekday($custom_date)
{
$week_start = date(‘d-m-Y‘, strtotime(‘this week monday‘, $custom_date));
$week_end = date(‘d-m-Y‘, strtotime(‘this week sunday‘, $custom_date));
$week_array[0] = $week_start;
$week_array[1] = $week_end;
return $week_array;
}
echo ‘
Weeks in 2013
‘ . getIsoWeeksInYear(2013);
$weekday = weekday(strtotime(date(‘d-m-Y‘, strtotime(‘5-8-2013‘))));
echo ‘
10-8-2013‘;
echo ‘
Start: ‘ . $weekday[0];
echo ‘
End: ‘ . $weekday[1];
?>
上一篇:HTML入门