参考: https://blog.youkuaiyun.com/qq_16399991/article/details/72529477
cho strtotime("+1 year");//返回时间戳, 如果要转换成一般时间格式还需要下面的函数
echo date('Y-m-d H:i:s', strtotime("+1 year"));
==============================================
同理,不仅仅可以+year 还可以是天, 月日都可以的,如下代码:
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
对于给定日期:
先把字符串转为date,然后+1 year,最后注意是不是UTC日期格式
$created_time = strtotime($row->created_at);
$expire_date = date('Y-m-d H:i:s', strtotime('+1 year', $created_time));
$expire_date = DatetimeHelper::convertUTC($expire_date);
本文介绍如何使用PHP进行日期和时间的处理,包括将字符串转换为日期、增加年份以及其他复杂的时间间隔运算。通过实例展示了strtotime函数的强大功能及其配合date函数使用的技巧。
1633

被折叠的 条评论
为什么被折叠?



