//do some test 求今天的开始时间和结束时间
$timestamp = time();
$beginOfDay = strtotime("midnight", $timestamp);
$endOfDay = $beginOfDay + 60 * 60 * 24 - 1;
echo date('Y-m-d H:i:s e',$beginOfDay);
echo '<br>';
echo date('Y-m-d H:i:s e',$endOfDay);
//这个周末的开始时间和结束时间
$beginOfWeek = strtotime('monday this week');
$endofWeek = $beginOfWeek + 7 * 60 * 60 * 24 -1;
echo '<br>';
echo date('Y-m-d H:i:s e',$beginOfWeek);
echo '<br>';
echo date('Y-m-d H:i:s e',$endofWeek);
$beginOfWeek = strtotime('monday this week') - 60 * 60 * 24 * 7;
$endofWeek = $beginOfWeek + 7 * 60 * 60 * 24 -1;
echo '<br>';
echo date('Y-m-d H:i:s e',$beginOfWeek);
echo '<br>';
echo date('Y-m-d H:i:s e',$endofWeek);
//时,分,秒,月,日,年
$month = 2;
$year = 2016;
$beginOfMonth = mktime(0,0,0,$month,1,$year) ;
$endofMonth = mktime(0,0,0,$month + 1,1,$year) - 1;;
echo '<br>';
echo date('Y-m-d H:i:s e',$beginOfMonth);
echo '<br>';
echo date('Y-m-d H:i:s e',$endofMonth);
1
wd0g 2016-02-29 10:02:05 +08:00
代码可以在简化下撒
|
2
inmyfree 2016-03-02 10:05:41 +08:00
第一个...
$timestamp = time(); echo $startDate = date("Y-m-d 00:00:00 e",$timestamp); echo $endDate = date("Y-m-d 23:59:59 e",$timestamp ); 第二个 $timemsp = time(); $weekIndex = date ( "w", $timemsp ); // 一周的第几天 $endIndex = 7 - $weekIndex; // 周日是几天后 $weekIndex = $weekIndex - 1; echo $weekStart = date("Y-m-d 00:00:00 e", strtotime ("-$weekIndex day", $timemsp )); // 计算周一 echo $weekEnd = date("Y-m-d 23:59:59 e", strtotime ("+$endIndex day", $timemsp )); // 计算周末 第三个 $timemsp = time(); echo $firstday = date('Y-m-01 00:00:00 e',$timemsp);//开始时间所在月的第一天 echo $lastday = date('Y-m-d 23:59:59 e',strtotime("$firstday +1 month -1 day",$timemsp));//这个月最后一天 |