<?php
function GetWeekList($year,$weekcurrent)
{
if ($year%4==0 && ($year%100!=0 || $year%400==0))
{
$days=366;
}
else
{
$days=365;
}
$weeks=substr($days/7,0,2);//计算一年有多少个星期
$weeklist=array();
$wc=1;
for($w=0;$w<$weekcurrent-1;$w++)
{
$WeekDate=GetWeekDate($year,$wc,'3');
$startime=date("Y-m-d",$WeekDate[0]);
$endtime=date("Y-m-d",$WeekDate[1]);
$weeklist[$w]["id"]=$wc;
$weeklist[$w]["name"]=$year." 年, 第 ".$wc." 周 ($startime - $endtime)";
$wc++;
}
return $weeklist;
}
/计算一周的开始结束时间//
function GetWeekDate($year,$week,$startcount)
{
$timestamp = mktime(0,0,0,1,1,$year);
$dayofweek = date("w",$timestamp);
$distance = ($week-1)*7-$dayofweek+1+$startcount;
$passed_seconds = $distance * 86400;
$timestamp += $passed_seconds;
$first_date_of_week = $timestamp; //date("Ymd",$timestamp);
$distance = 7;
$timestamp += $distance * 86400;
$last_date_of_week = $timestamp; //date("Ymd",$timestamp);
$startime=$first_date_of_week;
$endtime=$last_date_of_week;
$WeekDate=array($startime,$endtime);
return $WeekDate;
}
function GetMonthList($year,$monthcurrent)
{
$mc=1;
for($m=0;$m<12;$m++)
{
$monthlist[$m]["id"]=$mc;
$monthlist[$m]["name"]=$year." 年,".$mc." 月 ";
$mc++;
}
return $monthlist;
}
///计算一个月的开始结束时间//
function GetMonthDate($year,$month)
{
if($month<10)
{
$month="0".$month;
}
$startime=$year."-".$month."-01";
//$months1=array(1,3,5,7,8,10,12);
$months=array(4,6,9,11);
if($month=="2")
{
if ($year%4==0 && ($year%100!=0 || $year%400==0))
{
$endtime=$year."-".$month."-29 24:00:00";
}
else
{
$endtime=$year."-".$month."-28 24:00:00";
}
}
else if(in_array($month,$months))
{
$endtime=$year."-".$month."-30 24:00:00";
}
else
{
$endtime=$year."-".$month."-31 24:00:00";
}
$MonthDate=array($startime,$endtime);
return $MonthDate;
}
?>
转载于:https://www.cnblogs.com/flowers-yang/archive/2012/12/06/2805540.html