Chinaunix
标题:
【转】php 时间,日期计算
[打印本页]
作者:
中关村村草
时间:
2011-11-15 14:33
标题:
【转】php 时间,日期计算
【转】php 时间,日期计算
转自:
http://www.oschina.net/code/snippet_4873_3145
Php代码
1.<?php
2.//output: 2010-1-2
3.//int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year]]]]]] )
4.echo $test = date( 'Y-m-d', mktime(0,0,0,12+1,1+1,2009))."<br>";
5.//明天
6.echo $tomorrow = date( 'Y-m-d', mktime(0,0,0,date('m') ,date('d')+1,date('Y')))."<br>";
7.//昨天
8.echo $yesterday = date( 'Y-m-d',mktime(0,0,0,date('m') ,date('d')-1,date('Y')))."<br>";
9.//上一个月
10.echo $lastmonth = date( 'Y-m-d', mktime(0,0,0,date('m')-1,date('d'), date('Y')))."<br>";
11.//下一年
12.echo $nextyear = date( 'Y-m-d', mktime(0,0,0,date('m'), date('d'), date('Y')+1))."<br>";
13.//明天
14.echo $tomorrow = date('Y-m-d',strtotime ('+1 day'))."<br>"; //明天
15./*echo strtotime("now"), "\n";
16.echo strtotime("10 September 2000"), "\n";
17.echo strtotime("+1 day"), "\n";
18.echo strtotime("+1 week"), "\n";
19.echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
20.echo strtotime("next Thursday"), "\n";
21.echo strtotime("last Monday"), "\n"; */
22.
23.//使用strtotime增加日期
24.echo $date1 = strtotime('2010-08-09')."<br>";
25.echo date('Y-m-d',strtotime("+5 day",$date1));
26. //相应地,要增加月,年,将day改成month或year即可
27.
28.
29.?>
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2