首页 > 其他 > 详细

获得自然日周月时间

时间:2014-12-06 16:40:45      阅读:259      评论:0      收藏:0      [点我收藏+]
1.以下函数都可以直接使用。
function getReportDates($periods){
$dates = array();
//当前时间周期的起止时间
$end = getWeekendByDate($periods);
$start = date("Y-m-d",strtotime("-".($periods-1). "day",strtotime($end)));
//获取日期($times个周期)
$dates[‘start‘] = $start." 00:00:00";
$dates[‘end‘] = $end." 23:59:59";
return $dates;
}

/**
* 获取自然 天,周,月
* @param date:今天的日期
* @return array:开始时间和结束时间.
*/
function getWeekendByDate($periods){ //$periods是要的天数 1 7 30

$st = array(1=>‘day‘,7=>‘week‘,30=>‘month‘);

if(array_key_exists($periods,$st)){
        $type = $st[$periods];
}else{
$type = ‘‘;
}

switch($type){
case ‘week‘:
$day = date(‘N‘, time()); //当前日期是星期几
if($day<2){
return date("Y-m-d", time() - 86400 * ($day+7));
}else {//得到上一周的周末日期。
return date("Y-m-d", time() - 86400 * $day);
}
case ‘day‘:
return date("Y-m-d", time() - 86400 * 2); // 返回前天的日期
case ‘month‘:
if((int)date("d",time())<2){
return date("Y-m-d",strtotime(date("Y-m-0",strtotime("-1 month",strtotime(date("Y-m",time()))))));
}else{
return date("Y-m-d",strtotime(date("Y-m-0",time())));
}
default:
return date("Y-m-d",strtotime("-1 day")); //每天的前一天
}
}

获得自然日周月时间

原文:http://www.cnblogs.com/kobigood/p/4148315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!