php 获取时间,时间戳(上周,上月,上半年,上一年,自定义时间),strtotime(),date()

来源:互联网 发布:adobe cc2017 mac破解 编辑:程序博客网 时间:2024/05/23 19:34
date_default_timezone_set('PRC');$last_week_first = strtotime(date('Y-m-01', strtotime('-1 week')));$last_week_last =  strtotime(date('Y-m-d',$last_week_first)."+1 week -1 day");$last_month_first = strtotime(date('Y-m-01', strtotime('-1 month')));$last_month_last =  strtotime(date('Y-m-d',$last_month_first)."+1 month -1 day");$last_half_first = strtotime(date('Y-06-01', strtotime('-6 month')));$last_half_last =  strtotime(date('Y-m-d',$last_half_first)."+6 month -1 day");$last_year_first = strtotime(date('Y-01-01', strtotime('-1 year')));$last_year_last =  strtotime(date('Y-m-d',$last_year_first)."+12 month -1 day");echo date('Y-m-d',$last_week_first);echo '<br />';echo date('Y-m-d',$last_week_last);echo '<br />';echo date('Y-m-d',$last_month_first);echo '<br />';echo date('Y-m-d',$last_month_last);echo '<br />';echo date('Y-m-d',$last_half_first);echo '<br />';echo date('Y-m-d',$last_half_last);echo '<br />';echo date('Y-m-d',$last_year_first);echo '<br />';echo date('Y-m-d',$last_year_last);

注 : 时间不包含当天,因为只获取到00:00,如果需要包含当天请把 -1 day 删除,包含当天,但多一秒

0 0
原创粉丝点击