PHP gets the timestamp one month after a specified date

You can use PHP's time function  strtotime() to get the timestamp one month after a specified date. The specific methods are as follows:

Suppose you want to get the timestamp of the next month on May 1, 2021. You can first convert the date into a timestamp, and then  strtotime() add one month of time through the function to get the timestamp of the next month.

code show as below:

$date = '2021-05-01'; // 指定日期
$timestamp = strtotime($date); // 将指定日期转换为时间戳
$next_month_timestamp = strtotime('+1 month', $timestamp); // 获取往后一个月的时间戳

echo "指定日期:".$date."<br>";
echo "指定日期时间戳:".$timestamp."<br>";
echo "往后一个月时间戳:".$next_month_timestamp."<br>";
echo "往后一个月日期:".date('Y-m-d', $next_month_timestamp)."<br>";

The above code will output something similar to the following:

指定日期:2021-05-01
指定日期时间戳:1619827200
往后一个月时间戳:1622505600
往后一个月日期:2021-06-01

It should be noted that if the specified date is not the last day of the current month, the time in the next month may not be the same day in the next month, but one month after the corresponding date of the current month. For example, if the specified date is April 15, 2021, the next month will be May 15, 2021, not May 1, 2021.

Guess you like

Origin blog.csdn.net/wuxiaoquan_520/article/details/131000669