PHP指定时间戳加上1天,1周,1月,一年实际上是不须要用上什么函数的!指定时间戳自己就是数字整型,咱们只须要再计算1天,1周它的秒数相加便可!php
博主搜索php指定时间戳加一天一年,结果许多的文章给出来的结果是用的函数:strtotime();这个函数的确是能够很好的帮助到你,用这个函数有两种方法能够实现:函数
第一:是你须要先把指定时间戳格式化再用这个函数才能加一天,一年.....;并且网上各大平台都没有讲到这个知识点!spa
第二:直接用这个函数的第2个参数,不少人用这个函数基本上是不用第2个参数的,默认的第2个参数是获得当前时间戳,同时咱们也能够自定义时间戳的;这个知识点互联网上更加的没有讲解到,连PHP手册也没有讲解到吧!code
<?php //http://127.0.0.1/date.php echo '当前时间戳例子:'; echo '<br>'; echo '当前时间戳:' . date('Y-m-d H:i:s', strtotime('now'));//当前时间戳 2017-01-09 21:04:11 echo '<br>'; echo '当前时间戳+1秒:' . date('Y-m-d H:i:s', strtotime('+1second'));//当前时间戳+1秒 2017-01-09 21:04:12 echo '<br>'; echo '当前时间戳+1分:' . date('Y-m-d H:i:s', strtotime('+1minute'));//当前时间戳+1分 2017-01-09 21:05:11 echo '<br>'; echo '当前时间戳+1小时:' . date('Y-m-d H:i:s', strtotime('+1hour'));//当前时间戳+1小时 2017-01-09 22:04:11 echo '<br>'; echo '当前时间戳+1天:' . date('Y-m-d H:i:s', strtotime('+1day'));//当前时间戳+1天 2017-01-10 21:04:11 echo '<br>'; echo '当前时间戳+1周:' . date('Y-m-d H:i:s', strtotime('+1week'));//当前时间戳+1周 2017-01-16 21:04:11 echo '<br>'; echo '当前时间戳+1月:' . date('Y-m-d H:i:s', strtotime('+1month'));//当前时间戳+1月 2017-02-09 21:04:11 echo '<br>'; echo '当前时间戳+1年:' . date('Y-m-d H:i:s', strtotime('+1year'));//当前时间戳+1年 2018-01-09 21:04:11 echo '<br>'; echo '当前时间戳+12年,12月,12天,12小时,12分,12秒:' . 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 '<br>'; echo '<br>'; echo '指定时间戳例子:'; echo '<br>'; $t = 1575302400;//指定时间戳 echo '指定时间:' . $dt = date('Y-m-d H:i:s', $t);//2019-12-02 16:00:00 echo '<br>'; echo '<br>'; /*方法一*/ echo '指定时间+1天:' . date('Y-m-d H:i:s', $t + 1 * 24 * 60 * 60);//指定时间+1天:2019-12-03 16:00:00 echo '<br>'; echo '指定时间+1月:' . date('Y-m-d H:i:s', $t + 31 * 24 * 60 * 60);//指定时间+1月:2020-01-02 16:00:00 echo '<br>'; echo '指定时间+1年:' . date('Y-m-d H:i:s', $t + 365 * 24 * 60 * 60);//指定时间+1年:2020-12-01 16:00:00 echo '<br>'; echo '<br>'; /*方法二*/ //$dt是指定时间戳格式化后的日期 echo '指定时间+1天:' . date('Y-m-d H:i:s', strtotime("$dt+1day"));//指定时间+1天:2019-12-03 16:00:00 echo '<br>'; echo '指定时间+1月:' . date('Y-m-d H:i:s', strtotime("$dt+1month"));//指定时间+1月:2020-01-02 16:00:00 echo '<br>'; echo '指定时间+1年:' . date('Y-m-d H:i:s', strtotime("$dt+1year"));//指定时间+1年:2020-12-02 16:00:00 echo '<br>'; echo '<br>'; /*方法三*/ //$t是指定时间戳 echo '指定时间+1天:' . date('Y-m-d H:i:s', strtotime("+1day", $t));//指定时间+1天:2019-12-03 16:00:00 echo '<br>'; echo '指定时间+1月:' . date('Y-m-d H:i:s', strtotime("+1month", $t));//指定时间+1月:2020-01-02 16:00:00 echo '<br>'; echo '指定时间+1年:' . date('Y-m-d H:i:s', strtotime("+1year", $t));//指定时间+1年:2020-12-02 16:00:00 echo '<br>'; echo '<br>';
执行效果:blog