0
点赞
收藏
分享

微信扫一扫

[PHP]php将时间戳增加一年


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);

 

举报

相关推荐

0 条评论