远昔在此分享 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天
发表评论