折雨的天空
PHP日期的加减,比如加1年,减一年
2023-6-17 我好笨


以前用strtotime进行处理,现在手册上不推荐这个方法了。



使用DateTime处理,如下:



//日期加一年
$tmpSqlStartDate=new DateTime($startData);
$tmpSqlStartDate->sub(new DateInterval('P1Y'));
$sqlStartDate=$tmpSqlStartDate->format('Y-m');

//日期减一年
$data=new DateTime($current);
$data->sub(new DateInterval('P1Y'));


//单位支持:
y 多少年。
m 多少月。
d 多少天。
h 多少小时。
i 多少分钟。
s 多少秒。
f 多少微秒。



发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容