php strtotime函数常见用法

远昔 代码记录 2024-04-28 302 1

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

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

1.日期时间字符串转换为 UNIX 时间戳:
$timestamp = strtotime('2024-04-20 10:30:00');  //1713580200


2.相对时间转换为 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() 函数常见的用法,可以根据具体需求选择合适的方式来进行日期时间字符串的解析。

评论

发表评论:

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论
精彩评论
  • 2024-05-01 08:27:30

    五一购买授权有活动吗?