如何在给定日期的情况下获得未来一个月的Unix时间戳

Fin*_*orm 10 php

假设我从数据库中提取一个字段,即时间戳字段.

如何从该时间戳字段获取未来1个月的Unix时间戳?

我的大脑有点累,所以我需要一点点慢跑.

jon*_*ohn 25

$newDate = strtotime('+1 month',$startDate); 
Run Code Online (Sandbox Code Playgroud)

使用strtotime()你可以传递'+1个月'来添加一个上下文敏感的月份.


Pas*_*TIN 7

我会使用该strtotime()函数,添加+1 month到您的时间戳:

$future = strtotime('+1 month', $current_time);
Run Code Online (Sandbox Code Playgroud)


有了strtotime(),你不必考虑自己"像一个月30天,其他人有31",或"2月有时有28天,有时29".

毕竟,添加一个月到一个日期有点困难,添加30*24*3600秒......


您也可以使用DateTime类和方法,如DateTime::modify()DateTime::add().