1 2 3 4 5 6 7 8 9 10 11 12 | strtotime ("now"); strtotime ("10 September 2017"); strtotime ("+1 day"); strtotime ("+1 week"); strtotime ("+1 week 2 days 4 hours 2 seconds"); strtotime ("next Thursday"); strtotime ("last Monday"); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | $times = []; function makeTime(){ //获取今日开始时间戳和结束时间戳 $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; $times['today']['begin'] = $beginToday; $times['today']['end'] = $endToday; //获取昨日起始时间戳和结束时间戳 $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y')); $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1; $times['yesterday']['begin'] = $beginYesterday; $times['yesterday']['end'] = $endYesterday; //获取上周起始时间戳和结束时间戳 $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')); $times['lastWeek']['begin'] = $beginLastweek; $times['lastWeek']['end'] = $endLastweek; //获取本月起始时间戳和结束时间戳 $beginThismonth=mktime(0,0,0,date('m'),1,date('Y')); $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y')); $times['thisMonth']['begin'] = $beginThismonth; $times['thisMonth']['end'] = $endThismonth; //获取本周开始时间和结束时间,此例中开始时间为周一 $defaultDate = date('Y-m-d'); $first = 1; $w = date('w',strtotime($defaultDate)); $beginWeek = strtotime("$defaultDate-" . ($w?$w-$first:6) . 'days'); $endWeek = $beginWeek + 6*24*3600-1; $times['thisWeek']['begin'] = $beginWeek; $times['thisWeek']['end'] = $endWeek; //获取上月的起始时间戳和结束时间戳 $beginLastmonth=mktime(0,0,0,date('m')-1,1,date('Y')); $endLastmonth=mktime(23,59,59,date('m')-1,date('t'),date('Y')); $times['LastMonth']['begin'] = $beginLastmonth; $times['LastMonth']['end'] = $endLastmonth; //获取今年的起始时间和结束时间 $beginThisyear = mktime(0,0,0,1,1,date('Y')); $endThisyear = mktime(23,59,59,12,31,date('Y')); $times['thisYear']['begin'] = $beginThisyear; $times['thisYear']['end'] = $endThisyear; //获取上年的起始时间和结束时间 $beginLastyear = mktime(0,0,0,1,1,date('Y')-1); $endLastyear = mktime(23,59,59,12,31,date('Y')-1); $times['lastYear']['begin'] = $beginLastyear; $times['lastYear']['end'] = $endLastyear; //获取本季度开始时间和结束时间 $season = ceil((date('n'))/3);//当月是第几季度 $beginThisSeason = mktime(0, 0, 0,$season*3-3+1,1,date('Y')); $endThisSeason = mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y')); $times['thisSeason']['begin'] = $beginThisSeason; $times['thisSeason']['end'] = $endThisSeason; //获取上季度的起始时间和结束时间 $beginLastSeason = mktime(0, 0, 0,($season-1)*3-3+1,1,date('Y')); $endLastSeason = mktime(23,59,59,($season-1)*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y')); $times['lastSeason']['begin'] = $beginLastSeason; $times['lastSeason']['end'] = $endLastSeason; return $times; } $times = makeTime(); |
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |