【转】php 时间,日期计算

转自: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即可


?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值