Mar132012
php时间处理函数
作者:黑♂白 发布:2012-03-13 10:34:49 分类: web后端
php 时间一般都采用大整数的是形式存储和调用。 time() 函数返回当前时间的 Unix 时间戳。
<?php
$t=time();
$nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
echo $t;
echo $nextWeek;
?>
strtotime(time,now) 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。
<?php
echo(strtotime("now"));
echo(strtotime("3 October 2005"));
echo(strtotime("+5 hours"));
echo(strtotime("+1 week"));
echo(strtotime("+1 week 3 days 7 hours 5 seconds"));
echo(strtotime("next Monday"));
echo(strtotime("last Sunday"));
?>
date(format,timestamp)函数可把时间戳格式化为可读性更好的日期和时间。
<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
echo date('Y年m月d日',time());
?>
理解上面三个函数,就可以很好地在php中操作日期了。
您还未登录,需要登录后才能发言