PHP specifies the timestamp plus 1 day, 1 week, and January

PHP specifies the timestamp plus one day, one week, one month, one year, in fact, there is no need to use any function! The specified timestamp itself is a numeric integer, we only need to calculate 1 day, 1 week and its seconds can be added together!

The blogger searches for the php specified timestamp plus one day and one year, and the results given in many articles are the function: strtotime(); this function can really help you very well, there are two ways to achieve this function : First: You need to format the specified timestamp first and then use this function to add one day, one year...; and the major online platforms have not mentioned this knowledge point! Second: Use the second parameter of this function directly. Many people basically use this function without the second parameter. The default second parameter is to get the current timestamp, and we can also customize the timestamp; This knowledge point is even more unexplained on the Internet, even the PHP manual hasn't explained it!

For details, please refer to the PHP function: strtotime();

The following are several ways for bloggers to realize the PHP specified period plus one day and one year!

echo date('Y-m-d H:i:s',strtotime('now'));//当前时间戳 2017-01-09 21:04:11
echo date('Y-m-d H:i:s',strtotime('+1second'));//当前时间戳+1秒 2017-01-09 21:04:12
echo date('Y-m-d H:i:s',strtotime('+1minute'));//当前时间戳+1分 2017-01-09 21:05:11
echo date('Y-m-d H:i:s',strtotime('+1hour'));//当前时间戳+1小时 2017-01-09 22:04:11
echo date('Y-m-d H:i:s',strtotime('+1day'));//当前时间戳+1天 2017-01-10 21:04:11
echo date('Y-m-d H:i:s',strtotime('+1week'));//当前时间戳+1周 2017-01-16 21:04:11
echo date('Y-m-d H:i:s',strtotime('+1month'));//当前时间戳+1月 2017-02-09 21:04:11
echo date('Y-m-d H:i:s',strtotime('+1year'));//当前时间戳+1年 2018-01-09 21:04:11
echo date('Y-m-d H:i:s',strtotime('+12year 12month 12day 12hour 12minute 12second'));//当前时间戳+12年,12月,12天,12小时,12分,12秒 2030-01-22 09:16:23
echo $dt=date('Y-m-d H:i:s',$t);//2017-01-09 21:10:16
echo date('Y-m-d H:i:s',$t+1*24*60*60);//指定时间戳+1天 2017-01-10 21:10:16
echo date('Y-m-d H:i:s',$t+365*24*60*60);//指定时间戳+1年 2018-01-09 21:10:16
echo date('Y-m-d H:i:s',strtotime("$dt+1day"));//指定时间戳+1天 2017-01-10 21:10:16
echo date('Y-m-d H:i:s',strtotime("$dt+1year"));//指定时间戳+1年 2018-01-09 21:10:16
echo date('Y-m-d H:i:s',strtotime("+1day",$t));//指定时间戳+1天 2017-01-10 21:10:16
echo date('Y-m-d H:i:s',strtotime("+1year",$t));//指定时间戳+1年 2018-01-09 21:10:16

Guess you like