Chinaunix

标题: 【转】php 时间,日期计算 [打印本页]

作者: 中关村村草    时间: 2011-11-15 14:33
标题: 【转】php 时间,日期计算
【转】php 时间,日期计算





转自:http://www.oschina.net/code/snippet_4873_3145


Php代码
  1. 1.<?php   
  2. 2.//output: 2010-1-2   
  3. 3.//int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year]]]]]] )   
  4. 4.echo $test = date( 'Y-m-d', mktime(0,0,0,12+1,1+1,2009))."<br>";   
  5. 5.//明天   
  6. 6.echo $tomorrow = date( 'Y-m-d', mktime(0,0,0,date('m') ,date('d')+1,date('Y')))."<br>";   
  7. 7.//昨天   
  8. 8.echo $yesterday = date( 'Y-m-d',mktime(0,0,0,date('m') ,date('d')-1,date('Y')))."<br>";   
  9. 9.//上一个月   
  10. 10.echo $lastmonth = date( 'Y-m-d', mktime(0,0,0,date('m')-1,date('d'), date('Y')))."<br>";   
  11. 11.//下一年   
  12. 12.echo $nextyear = date( 'Y-m-d', mktime(0,0,0,date('m'), date('d'), date('Y')+1))."<br>";   
  13. 13.//明天   
  14. 14.echo $tomorrow = date('Y-m-d',strtotime ('+1 day'))."<br>"; //明天   
  15. 15./*echo strtotime("now"), "\n";  
  16. 16.echo strtotime("10 September 2000"), "\n";  
  17. 17.echo strtotime("+1 day"), "\n";  
  18. 18.echo strtotime("+1 week"), "\n";  
  19. 19.echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";  
  20. 20.echo strtotime("next Thursday"), "\n";  
  21. 21.echo strtotime("last Monday"), "\n"; */  
  22. 22.  
  23. 23.//使用strtotime增加日期   
  24. 24.echo $date1 = strtotime('2010-08-09')."<br>";   
  25. 25.echo date('Y-m-d',strtotime("+5 day",$date1));   
  26. 26. //相应地,要增加月,年,将day改成month或year即可   
  27. 27.  
  28. 28.  
  29. 29.?>  
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2