php strtotime常见用法

strtotime() 函数在 PHP 中用于将日期时间字符串转换为 UNIX 时间戳,它可以解析包括英文描述的日期时间字符串。以下是 strtotime() 函数的一些常见用法:

日期时间字符串转换为 UNIX 时间戳:

php 复制代码
$timestamp = strtotime('2024-04-20 10:30:00');

相对时间转换为 UNIX 时间戳:

php 复制代码
// 当前时间的前一天
$timestamp = strtotime('-1 day');
// 当前时间的后一周
$timestamp = strtotime('+1 week');

解析英文日期时间描述:

php 复制代码
// 下周五
$timestamp = strtotime('next Friday');
// 2小时后
$timestamp = strtotime('+2 hours');
// 上个月的第一天
$timestamp = strtotime('first day of last month');

解析相对日期时间描述:

php 复制代码
// 3天后的下午3点
$timestamp = strtotime('3 days 15:00');
// 明年的1月1日
$timestamp = strtotime('next year January 1');

指定基准时间进行解析:

php 复制代码
// 在指定时间基础上加上3天
$timestamp = strtotime('+3 days', $baseTimestamp);

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

相关推荐
zzzb1234561 小时前
WSL(Ubuntu)部署Nginx\+PHP8\.2完整教程(新手友好\+避坑指南)
linux·nginx·ubuntu·php
day day day ...2 小时前
Maven 项目中导入依赖的各种场景、方法、常见问题及解决办法
java·php·maven
拍客圈17 小时前
内容页底部 采集的同时 隐瞒封面图
服务器·php
tryqaaa_21 小时前
学习日志(二)【linux全部命令,http请求头{有例题},Php语法学习】
linux·学习·http·php·web
Johnstons1 天前
网络故障定位工具怎么搭配:Wireshark、tcpdump、监控平台各自该在什么时候上场?
数据分析·wireshark·php·es·tcpdump·网络故障定位工具搭配与选型
aq55356001 天前
Laravel 10.x重磅升级:PHP 8.1+新时代
开发语言·php·laravel
QCzblack1 天前
php-ser-libs
android·开发语言·php
代龙涛1 天前
WordPress archive.php 分类与归档页面开发指南
开发语言·后端·php·wordpress
YaBingSec1 天前
玄机靶场—Apache-druid(CVE-2021-25646) WP
java·开发语言·笔记·安全·php·apache
BingoGo1 天前
使用 PHP TrueAsync 改造 Laravel 协程异步化的可行路径
php·laravel