php中如何将date转为timestamp

这篇文章给大家分享的是有关php中如何将date转为timestamp的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

我们提供的服务有:网站设计、做网站、微信公众号开发、网站优化、网站认证、德安ssl等。为上1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的德安网站制作公司

在PHP中,可以使用strtotime()函数来将date(日期)转为timestamp(时间戳),该函数可以将任何字符串的日期时间描述解析为Unix时间戳,语法格式“strtotime(字符串形式的日期)”。

本教程操作环境:windows7系统、PHP7.1版,DELL G3电脑

php将date(日期)转为timestamp(时间戳)

";    //输出 1620979210
echo strtotime("10 September 2021")."
";    //输出 1631203200 echo strtotime("+1 day"), ""."
";    //输出明天此时的时间戳  ?>

输出:

1622707210
1631203200
1622787020

说明:

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

int strtotime ( string time [, int now] )
参数描述
time必需。规定日期/时间字符串。
now可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。

示例:

";
echo strtotime("now")."
"; echo strtotime("10 September 2021")."
"; echo strtotime("+1 day")."
"; echo strtotime("+1 week")."
"; echo strtotime("+1 week 2 days 4 hours 2 seconds")."
"; echo strtotime("next Thursday")."
"; echo strtotime("last Monday")."
"; ?>

输出:

1622700860
1622700860
1631203200
1622787260
1623305660
1623492862
1623254400
1622390400

感谢各位的阅读!关于“php中如何将date转为timestamp”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


网站题目:php中如何将date转为timestamp
转载来源:http://scyanting.com/article/jdhicp.html