例如:
echo "时间戳:".mktime().'<br>';//返回当前时间戳
echo "任意日期:".date("Y-m-d",mktime(0,0,0,2,21,1996)).'<br>';
echo "当前日期: ".date("Y-m-d",mktime()).'<br>';
运行结果为:
时间戳:1458979695 任意日期:1996-02-21 当前日期: 2016-03-26
获取当前时间戳
PHP通过time()函数获取当前的UNIX时间戳。
语法如下:
int time(void);
该函数没有参数,返回值为UNIX时间戳的整数值。
例如:
echo time()."<br>";//输出当前时间戳
$nextWeek = time()+(7*24*60*60);//一个星期七天,一天24小时,一个小时60分,一分60秒
echo "Now: ".date("Y-m-d")."<br>";
echo "Next Week: ".date("Y-m-d",$nextWeek);
运行结果为
1458980073 Now: 2016-03-26 Next Week: 2016-04-02
将英文文本的日期时间描述解析为UNIX时间戳
strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。
语法
strtotime(time,now)
| 参数 | 描述 |
|---|---|
| time | 规定要解析的时间字符串。 |
| now | 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 |







