php把日期转成时间戳的方法:可以利用strtotime()函数来实现。strtotime()函数可以将任何字符串的日期时间描述解析为Unix时间戳,若成功则返回时间戳,失败则返回false。

strtotime() 函数将任何字符串的日期时间描述解析为 Unix 时间戳,成功则返回时间戳,失败则返回 FALSE。
(推荐教程:php图文教程)
语法:
int strtotime ( string $time [, int $now = time() ] )
参数:
立即学习“PHP免费学习笔记(深入)”;
time 必需。规定日期/时间字符串。
now 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
(视频教程推荐:php视频教程)
举例:
<?php
// 设置时区
date_default_timezone_set("PRC");
$time = strtotime("2018-01-18 08:08:08");
// 将指定日期转成时间戳
// 打印当前时间 PHP_EOL 换行符,兼容不同系统
echo $time, PHP_EOL;
// 更多实例
echo strtotime("now"), PHP_EOL;
echo strtotime("now"), PHP_EOL;
echo strtotime("10 September 2000"), PHP_EOL;
echo strtotime("+1 day"), PHP_EOL;
echo strtotime("+1 week"), PHP_EOL;
echo strtotime("+1 week 2 days 4 hours 2 seconds"), PHP_EOL;
echo strtotime("next Thursday"), PHP_EOL;
echo strtotime("last Monday"), PHP_EOL;
?>以上就是php怎样把日期转成时间戳的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号