php如何把日期转为时间戳

2020-08-12 17:54:44

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

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

(推荐教程:php教程)

语法格式:

int strtotime ( string $time [, int $now = time() ] )

参数说明:

time 必需。规定日期/时间字符串。

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

代码实现:

<?phpecho strtotime("2009-10-21 16:00:10");//输出 1256112010echo strtotime("10 September 2008");//输出 1220976000echo strtotime("+1 day"), "<br />";//输出明天此时的时间戳?>
相关文章 大家在看