最近开始学php了,时间这块和c#还是有区别的,php在时间戳的基础上进行变换
1、获取当前时间(时间戳)
$now=time();
2、对指定时间(时间戳)进行操作
//时间戳
$date=strtotime('1 day',time());
$date=strtotime('1 month',time());
$date=strtotime('1 year',time());
3、对指定时间(字符串)进行操作
$endStr='2019/01/01'
$datestr=strtotime($endStr . ' +1 day');
4、获取当前的时间年初/年末/月初/月末
要注意如果精确到时分秒,不是从0开始,而是当前时间的时分秒
$yearStart = date('Y-m-d', strtotime('1/1'));
//"yearstart": "2020-01-01",
$yearEnd = date('Y-m-d h:m:s', strtotime('12/31'));
//"yearend": "2020-12-31 12:12:00",
$monStart=date('Y-m-01');
//"2020-02-01"
$monEnd=date('Y-m-t h:m:s');
//"2020-02-29 12:02:32",
5、时间戳与字符串互相转换
date(format,timestamp);//时间戳转字符串
$time=1582992000;
$date=date('Y-m-t h:m:s', $time);//2020/3/1 0:0:0
strtotime(datestr);//时间字符串转为时间戳
$date='2020/3/1 0:0:0';
$time=strtotime($date);