php获取今日、本周、本月、本年时间戳和日期格式
作者:互联网
//获取今日开始时间和结束时间时间戳格式和时间格式
$time1 = strtotime(date('Y-m-d 00:00:00',time()));
$time2 = strtotime(date('Y-m-d 23:59:59',time()));
$date1 = date('Y-m-d 00:00:00',time());
$date2 = date('Y-m-d 23:59:59',time());
//昨天时间
$time1 = strtotime(date('Y-m-d 00:00:00',time()-3600*24));
$time2 = strtotime(date('Y-m-d 23:59:59',time()-3600*24));
$date1 = date('Y-m-d 00:00:00',time()-3600*24);
$date2 = date('Y-m-d 23:59:59',time()-3600*24);
//本周时间
$time1 = mktime(0,0,0,date('m'),date('d')-date('N')+1,date('y'));
$time2 = mktime(23,59,59,date('m'),date('d')-date('N')+7,date('Y'));
$date1 = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("N")+1,date("Y")));
$date2 = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("N")+7,date("Y")));
//上周时间戳
$time1 = mktime(0,0,0,date('m'),date('d')-date('N')-6,date('Y'));
$time2 = mktime(23,59,59,date('m'),date('d')-date('N'),date('Y'));
$date1 = date('Y-m-d H:i:s', mktime(0,0,0, date('m'), date('d')-date('N')-6,date('Y')));
$date2 = date('Y-m-d H:i:s', mktime(23,59,59, date('m'), date('d')-date('N'),date('Y')));
//本月时间戳
$time1 = mktime(0,0,0,date('m'),1,date('Y'));
$time2 = mktime(23,59,59,date('m'),date('t'),date('Y'));
$date1 = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
$date2 = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
//上月时间戳
$time1 = strtotime(date('Y-m-01 00:00:00',strtotime('-1 month')));
$time2 = strtotime(date("Y-m-d 23:59:59", strtotime(-date('d').'day')));
$date1 = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
$date2 = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));
/**
* 获取指定年份内的所有月份
* @param $year 年份
* @return array
*/
public function getAllMonth($year)
{
$yeararr = [];
$month = [];
for ($i=1; $i <=12 ; $i++) {
$yeararr[$i] = $year.'-'.$i;
}
foreach ($yeararr as $key => $value) {
$timestamp = strtotime( $value );
$month[] = (int)date( 'Y-m', $timestamp );
}
return $month;
}
/**
* 获取指定时间内的所有日期
* @param $start 开始时间
* @param $end 结束时间
* @return array
*/
public function getNonthDays($start, $end)
{
$dt_start = strtotime($start);
$dt_end = strtotime($end);
while ($dt_start <= $dt_end) {
$value[] = date('m-d', $dt_start);
$dt_start = strtotime('+1 day', $dt_start);
}
return $value;
}
标签:00,59,23,strtotime,mktime,日期,date,格式,php 来源: https://blog.csdn.net/w18838020329/article/details/121923708