在php中可以通过strtotime函数将任何英文文本的日期或时间描述解析为Unix时间戳,其转换语法如“strtotime(time,now);”。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑 php怎么时间转unix时间? strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。 注意:如果年份表示使用两位数格式,则值 0-69 会映射为 2000-2069,值 70-100 会映射为 1970-2000。 注意:请注意 m/d/y 或 d-m-y 格式的日期,如果分隔符是斜线(/),则使用美洲的 m/d/y 格式。如果分隔符是横杠(-)或者点(.),则使用欧洲的 d-m-y 格式。为了避免潜在的错误,您应该尽可能使用 YYYY-MM-DD 格式或者使用 date_create_from_format() 函数。 语法 strtotime(time,now); 参数 time 必需。规定日期/时间字符串。 now 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 实例 将英文文本日期时间解析为 Unix 时间戳: <?php
echo(strtotime("now") . "<br>");
echo(strtotime("15 October 1980") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
?>运行结果:
1624501247
1473004800
1624519247
1625106047
1625390452
1624809600
1624118400 推荐学习:《PHP视频教程》 以上就是php怎么将时间转unix时间的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |