主要使用到了 php 的时间函数 mktime。
官方文档:http://kr1.php.net/manual/zh/function.mktime.php
1 //php获取今日开始时间戳和结束时间戳 2 $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); 3 $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; 4 //php获取本周起始时间 5 $beginWeek = mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")); 6 $endWeek = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")); 7 //php获取昨日起始时间戳和结束时间戳 8 $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y')); 9 $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1; 10 //php获取上周起始时间戳和结束时间戳 11 $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); 12 $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')); 13 //php获取本月起始时间戳和结束时间戳 14 $beginThismonth=mktime(0,0,0,date('m'),1,date('Y')); 15 $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
1 //获取今天00:00 2 $todaystart = strtotime(date(‘Y-m-d’.’00:00:00′,time())); 3 //获取今天24:00 4 $todayend = strtotime(date(‘Y-m-d’.’00:00:00′,time()+3600*24)); 5 //统计今天注册的用户 6 $todayuser[‘create_time’] = array(between,”$todaystart,$todayend”); 7 $todaysum = $Users->where($todayuser)->count(); 8 9 10 //获取昨天00:00 11 $timestart = strtotime(date(‘Y-m-d’.’00:00:00′,time()-3600*24)); 12 //获取今天00:00 13 $timeend = strtotime(date(‘Y-m-d’.’00:00:00′,time())); 14 //统计昨天注册的用户 15 $map[‘create_time’] = array(between,”$timestart,$timeend”); 16 $daycount = $Users->where($map)->count(); 17 18 $this->assign(“todaysum”,$todaysum); 19 $this->assign(“daycount”,$daycount);