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 必需。规定日期/时间字符串。
立即学习“PHP免费学习笔记(深入)”;
now 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
代码实现:
<?php
echo strtotime("2009-10-21 16:00:10");
//输出 1256112010
echo strtotime("10 September 2008");
//输出 1220976000
echo strtotime("+1 day"), "<br />";//输出明天此时的时间戳
?>以上就是php如何把日期转为时间戳的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号