PHP指定时间戳/日期加一天,一年,一周,一月

转载地址  https://www.cnblogs.com/Uncle-liu/p/7423006.html

  1. <?php
  2. echo date('Y-m-d H:i:s',strtotime('now'));//当前时间戳 2017-01-09 21:04:11
  3.  
  4. echo date('Y-m-d H:i:s',strtotime('+1second'));//当前时间戳+1秒 2017-01-09 21:04:12
  5.  
  6. echo date('Y-m-d H:i:s',strtotime('+1minute'));//当前时间戳+1分 2017-01-09 21:05:11
  7.  
  8. echo date('Y-m-d H:i:s',strtotime('+1hour'));//当前时间戳+1小时 2017-01-09 22:04:11
  9.  
  10. echo date('Y-m-d H:i:s',strtotime('+1day'));//当前时间戳+1天 2017-01-10 21:04:11
  11.  
  12. echo date('Y-m-d H:i:s',strtotime('+1week'));//当前时间戳+1周 2017-01-16 21:04:11
  13.  
  14. echo date('Y-m-d H:i:s',strtotime('+1month'));//当前时间戳+1月 2017-02-09 21:04:11
  15.  
  16. echo date('Y-m-d H:i:s',strtotime('+1year'));//当前时间戳+1年 2018-01-09 21:04:11
  17.  
  18. 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
  19.  
  20.  
  21. $t=1483967416;//指定时间戳
  22. echo $dt=date('Y-m-d H:i:s',$t);//2017-01-09 21:10:16
  23.  
  24. /*方法一*/
  25. echo date('Y-m-d H:i:s',$t+1*24*60*60);//指定时间戳+1天 2017-01-10 21:10:16
  26. echo date('Y-m-d H:i:s',$t+365*24*60*60);//指定时间戳+1年 2018-01-09 21:10:16
  27.  
  28. /*方法二*/
  29. //$dt是指定时间戳格式化后的日期
  30. echo date('Y-m-d H:i:s',strtotime("$dt+1day"));//指定时间戳+1天 2017-01-10 21:10:16
  31. echo date('Y-m-d H:i:s',strtotime("$dt+1year"));//指定时间戳+1年 2018-01-09 21:10:16
  32.  
  33. /*方法三*/
  34. //$t是指定时间戳
  35. echo date('Y-m-d H:i:s',strtotime("+1day",$t));//指定时间戳+1天 2017-01-10 21:10:16
  36. echo date('Y-m-d H:i:s',strtotime("+1year",$t));//指定时间戳+1年 2018-01-09 21:10:16
  37.  
  38. //指定时间戳加1月、1周、1小时、1分、1秒原理同上;
1 //php获取今日开始时间戳和结束时间戳
 2 $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
 3 $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
 4 //php获取本周起始时间
 5 $beginWeek = mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y"));
 6 $endWeek = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));
 7 //php获取昨日起始时间戳和结束时间戳
 8 $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
 9 $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
10 //php获取上周起始时间戳和结束时间戳
11 $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
12 $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
13 //php获取本月起始时间戳和结束时间戳
14 $beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
15 $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值