天天看点

php把日期转成时间戳,php如何把日期转为时间戳

php把日期转为时间戳的方法是:可以使用strtotime()函数来实现。该函数可以将任何字符串的日期时间描述解析为Unix时间戳,失败则返回FALSE。具体使用方法如:【strtotime("2009-10-21 16:00:10")】。

php把日期转成时间戳,php如何把日期转为时间戳

strtotime() 函数将任何字符串的日期时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),成功则返回时间戳,失败则返回 FALSE。

(推荐教程:php教程)

语法格式:int strtotime ( string $time [, int $now = time() ] )

参数说明:time 必需。规定日期/时间字符串。

now 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。

代码实现:<?php

echo strtotime("2009-10-21 16:00:10");

//输出 1256112010

echo strtotime("10 September 2008");

//输出 1220976000

echo strtotime("+1 day"), "

";//输出明天此时的时间戳

?>