[PHP]常用时间戳获取-今年、去年、本月、上月、今日、昨日

Leave a comment

做数据处理常常用到,先记录一下。省的每次都翻写过的代码。

      echo mktime(0,0,0);//今日第一秒
      echo mktime(23,59,59);//今日最后一秒
      echo mktime(0,0,0,date('m'),date('d')-1,date('Y'));//昨日第一秒
      echo mktime(23,59,59,date('m'),date('d')-1,date('Y'));//昨日最后一秒
      echo mktime(0,0,0,date('m'),1,date('Y'));//本月1日
      echo mktime(23,59,59,date('m'),date('t'),date('Y'));//本月最后1日
      echo mktime(0,0,0,date('m',strtotime("-1 month")),1,date('Y',strtotime("-1 month")));//上月1日
      echo mktime(23,59,59,date('m',strtotime("-1 month")),date('t',strtotime("-1 month")),date('Y',strtotime("-1 month")));//上月最后1日
      echo mktime(0,0,0,1,1,date('Y'));//今年月1日
      echo mktime(23,59,59,12,date('t',strtotime("December")),date('Y'));//今年最后1日
      echo mktime(0,0,0,1,1,date('Y',strtotime("-1 year")));//去年月1日
      echo mktime(23,59,59,12,date('t',strtotime("December")),date('Y',strtotime("-1 year")));//去年最后1日

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注