首页 技术教程建站经验正文

php strtotime函数常见用法

kmwl520 建站经验 2024-06-13 16:26:46 114 0 PHP代码小白日志
小白日志

远昔在此分享 strtotime函数在 PHP 中用于将日期时间字符串转换为 UNIX 时间戳,它可以解析包括英文描述的日期时间字符串。

以下是 strtotime() 函数的一些常见用法:

PHP
1日期时间字符串转换为 UNIX 时间戳:
$timestamp  strtotime'2024-04-20 10:30:00'  //17135802002相对时间转换为 UNIX 时间戳:
$timestamp  strtotime'-1 day' //当前时间的前一天$timestamp  strtotime'+1 week' //当前时间的后一周3解析英文日期时间描述:
$timestamp  strtotime'next Friday' //下周五$timestamp  strtotime'+2 hours' //2小时后$timestamp  strtotime'first day of last month' //上个月的第一天4解析相对日期时间描述:
$timestamp  strtotime'3 days 15:00' //3天后的下午3点$timestamp  strtotime'next year January 1' //明年的1月1日5指定基准时间进行解析:
$timestamp  strtotime'+3 days' $baseTimestamp //在指定时间基础上加上3天

这些都是 strtotime() 函数常见的用法,可以根据具体需求选择合适的方式来进行日期时间字符串的解析。

发表评论

评论列表(0人评论 , 114人围观)
☹还没有评论,来说两句吧...

会员中心

探索精品网络资源的宝藏之地-歆梦资源网(775n.com)

https://123.775n.com/

| 京ICP备100000000

Powered By 某某网络科技有限公司

使用手机软件扫描微信二维码

关注我们可获取更多热点资讯