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

相关推荐
静听山水2 小时前
Redis的Pipeline (管道)
数据库·redis·php
hzb666663 小时前
unictf2026
开发语言·javascript·安全·web安全·php
JaguarJack3 小时前
PHP 应用遭遇 DDoS 攻击时会发生什么 从入门到进阶的防护指南
后端·php·服务端
YUJIANYUE12 小时前
PHP纹路验证码
开发语言·php
MZ_ZXD00114 小时前
springboot旅游信息管理系统-计算机毕业设计源码21675
java·c++·vue.js·spring boot·python·django·php
JMchen12316 小时前
Android后台服务与网络保活:WorkManager的实战应用
android·java·网络·kotlin·php·android-studio
AZ996ZA18 小时前
自学linux的第二十一天【DHCP 服务从入门到实战】
linux·运维·服务器·php
darkb1rd21 小时前
八、PHP SAPI与运行环境差异
开发语言·网络安全·php·webshell
darkb1rd21 小时前
七、PHP配置(php.ini)安全最佳实践
安全·php·webshell
JSON_L1 天前
Fastadmin中使用GatewayClient
php·fastadmin