欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【转】php 时间,日期计算 博客分类: php基础类 php时间计算日期计算 

程序员文章站 2024-03-24 08:07:22
...
转自:http://www.oschina.net/code/snippet_4873_3145

<?php
//output: 2010-1-2
//int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year]]]]]] )
echo $test = date( 'Y-m-d', mktime(0,0,0,12+1,1+1,2009))."<br>";
//明天
echo $tomorrow = date( 'Y-m-d', mktime(0,0,0,date('m') ,date('d')+1,date('Y')))."<br>";
//昨天
echo $yesterday = date( 'Y-m-d',mktime(0,0,0,date('m') ,date('d')-1,date('Y')))."<br>";
//上一个月
echo $lastmonth = date( 'Y-m-d', mktime(0,0,0,date('m')-1,date('d'), date('Y')))."<br>";
//下一年
echo $nextyear = date( 'Y-m-d', mktime(0,0,0,date('m'), date('d'), date('Y')+1))."<br>";
//明天
echo $tomorrow = date('Y-m-d',strtotime ('+1 day'))."<br>"; //明天
/*echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n"; */

//使用strtotime增加日期
echo $date1 = strtotime('2010-08-09')."<br>";
echo date('Y-m-d',strtotime("+5 day",$date1));
 //相应地,要增加月,年,将day改成month或year即可


?>