date时间
今日
年
$mtime= date("Y-m-d H:i:s", strtotime("-1 year"));
小时
$mtime= date("Y-m-d H:i:s", strtotime("-1 hour"));
一周
$mtime= date("Y-m-d H:i:s", strtotime("-1 week"));
天
$mtime= date("Y-m-d H:i:s", strtotime("-1 day"));
小时
$mtime= date("Y-m-d H:i:s", strtotime("-1 hour"));
分钟
$mtime= date("Y-m-d H:i:s", strtotime("-1 Minute"));
## 几秒前 几分钟前 几小时前 几天前 几月前 ##
function mdate($time = NULL) {
$text = '';
$time = $time === NULL || $time > time() ? time() : intval($time);
$t = time() - $time; //时间差 (秒)
$y = date('Y', $time)-date('Y', time());//是否跨年
switch($t){
case $t == 0:
$text = '刚刚';
break;
case $t < 60:
$text = $t . '秒前'; // 一分钟内
break;
case $t < 60 * 60:
$text = floor($t / 60) . '分钟前'; //一小时内
break;
case $t < 60 * 60 * 24:
$text = floor($t / (60 * 60)) . '小时前'; // 一天内
break;
case $t < 60 * 60 * 24 * 3:
$text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
break;
case $t < 60 * 60 * 24 * 30:
$text = date('m月d日 H:i', $time); //一个月内
break;
case $t < 60 * 60 * 24 * 365&&$y==0:
$text = date('m月d日', $time); //一年内
break;
default:
$text = date('Y年m月d日', $time); //一年以前
break;
}
return $text;
}
$today_start = date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y')));
$today_end = date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')+1,date('Y')-1));
//本月
$month_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
$month_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
//本周
$week_start= date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y')));
$week_end= date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7,date('Y')));
$arr['today_start'] = $today_start;
$arr['today_end'] =$today_end;
$arr['week_start'] = $week_start;
$arr['week_end'] =$week_end;
$arr['month_start'] = $month_start;
$arr['month_end'] =$month_end;
exit(json_encode($arr));
取得=当天0点的Unix时间戳
$day = strtotime(date('Ymd'));
echo date('Y-m-d H:i:s',$day);
取得昨天0点的Unix时间戳
$yesterday = strtotime(date('Ymd',strtotime('-1 day')));
echo date('Y-m-d H:i:s',$yesterday);
取得上周0点的Unix时间戳
$week = strtotime(date('Ymd',strtotime('-1 week')));
echo date('Y-m-d H:i:s',$week);
取得上月0点的Unix时间戳
$month = strtotime(date('Ymd',strtotime('-1 month')));
echo date('Y-m-d H:i:s',$month);
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$stimestamp = strtotime($startdate);
$etimestamp = strtotime($enddate);
// 计算日期段内有多少天
$days = ($etimestamp-$stimestamp)/86400+1;
// 保存每天日期
for($i=0; $i<$days; $i++ )
{
$date['start'] = date('Y-m-d H:i:s',$stimestamp+(86400*$i));
$date['end'] = date("Y-m-d H:i:s",mktime(0,0,0,date('m',$stimestamp+(86400*$i)),date('d',$stimestamp+(86400*$i))+1,date('Y',$stimestamp+(86400*$i)))-1);;
$day[]=$date;
}