标签:获取时间戳 start 需要 timezone this 中国 tar span date
1 //设置中国时区 2 date_default_timezone_set(‘PRC‘); 3 //今天的时间搓 4 $today_start = strtotime(date(‘Y-m-d‘,time()).‘ 0:0:0‘); 5 $today_end = strtotime(date(‘Y-m-d‘,time()).‘ 23:59:59‘); 6 //昨天的时间戳 7 $yesterday_start = strtotime(‘-1 day‘.‘ 0:0:0‘); 8 $yesterday_end = strtotime(‘-1 day‘.‘ 23:59:59‘); 9 //查看上个月日期 10 $first_day_of_month = date(‘Y-m‘,time()).‘-01 00:00:01‘; 11 $t = strtotime($first_day_of_month); 12 date(‘Y-m‘,$t); 13 date(‘Y-m‘,strtotime(‘- 1 month‘,$t)); 14 date(‘Y-m‘,strtotime(‘- 2 month‘,$t)); 15 16 //获取时间戳 17 方法一: 18 $yesterday_s = mktime(0,0,0,date(‘m‘),date(‘d‘)-1,date(‘Y‘));//昨天开始的时间搓 19 $yesterday_e = mktime(23,59,59,date(‘m‘),date(‘d‘)-1,date(‘Y‘));//昨天结束的时间搓 20 21 $tenday_s = mktime(0,0,0,date(‘m‘),date(‘d‘)-10,date(‘Y‘));//10天前开始的时间戳 22 $tenday_e = mktime(23,59,59,date(‘m‘),date(‘d‘)-10,date(‘Y‘));//10天前结束的时间戳 23 24 //方法二: 25 $yesterday_s = strtotime(date("Y-m-d",strtotime("-10 day")).‘ 0:0:0‘); //10天前开始的时间戳 26 $yesterday_e = strtotime(date("Y-m-d",strtotime("-10 day")).‘ 23:59:59‘);//10天前结束的时间戳 27 28 //方法三: 29 $day = $_REQUEST[‘day‘];//需要统计的日期 30 $time_s = strtotime($day.‘ 0:0:0‘); 31 $time_e = strtotime($day.‘ 23:59:59‘); 32 33 //获取本周一的时间戳 34 strtotime(date("Y-m-d",strtotime("-1 week Monday"))); 35 36 //获取今日开始时间戳和结束时间戳 37 $beginToday = mktime(0,0,0,date(‘m‘),date(‘d‘),date(‘Y‘)); 38 $endToday = mktime(0,0,0,date(‘m‘),date(‘d‘)+1,date(‘Y‘))-1; 39 40 //获取昨日起始时间戳和结束时间戳 41 $beginYesterday = mktime(0,0,0,date(‘m‘),date(‘d‘)-1,date(‘Y‘)); 42 $endYesterday = mktime(0,0,0,date(‘m‘),date(‘d‘),date(‘Y‘))-1; 43 44 //获取本周起始时间戳和结束时间戳 45 $beginThisweek = mktime(0,0,0,date(‘m‘),date(‘d‘)-date(‘w‘)+1,date(‘y‘)); 46 $endThisweek = time(); 47 48 //获取上周起始时间戳和结束时间戳 49 $beginLastweek = mktime(0,0,0,date(‘m‘),date(‘d‘)-date(‘w‘)+1-7,date(‘Y‘)); 50 $endLastweek = mktime(23,59,59,date(‘m‘),date(‘d‘)-date(‘w‘)+7-7,date(‘Y‘)); 51 52 //获取本月起始时间戳和结束时间戳 53 $beginThismonth = mktime(0,0,0,date(‘m‘),1,date(‘Y‘)); 54 $endThismonth = mktime(23,59,59,date(‘m‘),date(‘t‘),date(‘Y‘)); 55 56 //上个月的起始时间: 57 $begin_time = strtotime(date(‘Y-m-01 00:00:00‘,strtotime(‘-1 month‘))); 58 $end_time = strtotime(date("Y-m-d 23:59:59", strtotime(-date(‘d‘).‘day‘))); 59 60 $begin_year = strtotime(date("Y",time())."-1"."-1"); //本年开始 61 $end_year = strtotime(date("Y",time())."-12"."-31"); //本年结束 62 63 //现在的时间到第二天凌晨相差的时间戳 64 $time = (strtotime(date(‘Y-m-d‘))+3600*24) - time() ;
标签:获取时间戳 start 需要 timezone this 中国 tar span date
原文地址:https://www.cnblogs.com/dawuge/p/9056053.html