时间 日期

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;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jyvan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值