42
[minutes] => 16
[hours] => 13
[mday] => 23
[wday] => 2
[mon] => 2
[year] => 2010
[yday] => 53
[weekday] => tuesday
[month] => february
[0] => 1266902202
)
*///echo date(y-m-d h:i:s,-8000);
//setlocale(lc_all,zh_cn.gb2312); //setlocale函数对下面的没有影响。
#测试strftime,mktime函数。
echo strftime(今天是:%y-%m-%d %h:%m:%s).
;
echo strtotime(now).
; // 等于time(),但strtotime使用范围更灵活,参下文.
echo 测试还原昨天时间:.date(y-m-d,strtotime($lassdate)).
; //可以把字串型日期转成时间戳再用date转回原格式。
$x=strtotime($lassdate);
$y=mktime(0,0,0,2,22,2010);
echo strtotime()得到的昨天的时间戳是:.$x.,mktime()得到的昨天时间戳是:.$y.(($x==$y)?,二者相等:,二者不相同).
; //相等。
#显示1970年前的日期
$time_int=strtotime(1929-2-10);
echo date(y-m-d ,$time_int).
; //在mysql中与date()函数相同功能的是date_format(1996-02-05 11:07:45,%y-%m-%d)或for_format()
/*时间运算:
*请使用方法三。其它方法只供参考。 *
*/
#1、今天是23号,获得前天的时间,即减两天。
$predate=2;
$pretime=$predate*24*60*60; //2天的时间戳。
echo date(前天是:y-m-d,time()-$pretime).
; //前天是:2010-02-21
#2、两个日期相差的天数。
$olddate = 2010-02-11; //如果要用mktime函数,则要用explode拆解日期。
$oldtime = strtotime($olddate);
$passtime = time()-$oldtime; //经过的时间戳。
echo 你在网上泡了.floor($passtime/(24*60*60)).天了.
; //12天。
#3、去年这个时侯。使用时要考虑闰年:平年365天,闰年366天。
#方法一:用减去全年天数的时间戳来获取。
$ydate=1;
$ydate_y=date(y,time())-1; //年份-1,即去年
$ydateymd=$ydate_y-01-01;
$yymd=strtotime($ydateymd); //去年的1月1号时间戳。
$d=date(l,$yymd)?366:365; //是否是闰年
$yyeartime=$d*24*60*60;
$yyear=date(y-m-d,time()-$yyeartime);
echo 去年的今天:$yyear
; //2009-02-23
#方法二:用直接截取当前日期的年份减一,但不严谨,没有考虑到闰年。
#计算60年前的今天。忽略当中经过的闰年。
$ydate_y=$ydate_y-59;
$md=explode(-,date(y-m-d));
$yymd=$ydate_y-{$md[1]}-{$md[2]};
echo 60年前的今天:$yymd
; //1950-02-23
#方法三:用strtotime()和gnu日期语法---------推荐!
//3天后; //当前时间为2010-02-23
$d=strtotime(3 days);
echo 3天后.date(y-m-d,$d).
;
//3天前:
$d=strtotime(-3 days);
echo 3天前.date(y-m-d,$d).
; //2010-02-20
//一个月前:
$d=strtotime(-1 months);
echo 一个月前.date(y-m-d,$d).
; //2010-01-23
//2个月后:
$d=strtotime(2 months);
echo 二个月后.date(y-m-d,$d).
; //2010-04-23
//1年前:
$d=strtotime(-1 years);
echo 1年前.date(y-m-d,$d).
; //2009-02-23
//2小时前:
$d=strtotime(-2 hours);
echo 目前:.date(y-m-d h:i:s,time()).,2小时前.date(y-m-d h:i:s,$d).
; //目前:2010-02-23 13:38:49,2小时前2010-02-23 11:38:49
#datetime构造函数:object datetime([string $time [,datetimezone $timezone])
$date = new datetime(2010-02-23 12:26:36);
echo $date->format(y-m-d h:i:s).
; //和date()函数相同。2010-02-23 12:26:36
//重设时间:
//1、重设日期: boolean setdate(int year,int month,int day)
//2、重设时间: boolean setdate(int hour,int minute[,int second])
$date->setdate(2010,2,28);
echo $date->format(y-m-d h:i:s).
; //2010-02-28 12:26:36
//日期计算,相当于上面的strtotime()
$date->modify(+7 hours);
echo $date->format(y-m-d h:i:s).
; //2010-02-28 19:26:36
$date->modify(3 days);
echo $date->format(y-m-d h:i:s).
; //2010-03-03 19:26:36 //从上面被改过的28号开始
/*php5在win不支持money_format函数?
setlocale(lc_monetary,zh_cn);
echo money_format(%i,786.56);//?fatal error: call to undefined function money_format()
*/
?>
http://www.bkjia.com/phpjc/508431.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/508431.htmltecharticle?php //gb2312的encode header(cache-control: no-store, no-cache, must-revalidate); header(cache-control: post-check=0, pre-check=0, false); /*重点了解strtotime()函数 1、strf...