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

相关推荐
用户92724725021919 小时前
PHP+JS+CSS+JSON 单页新闻系统实现方案
php
Ashlee_code1 天前
什么是Web3?金融解决方案
开发语言·金融·架构·eclipse·web3·区块链·php
Sally璐璐1 天前
IPSAN 共享存储详解:架构、优化与落地实践指南
开发语言·php
程序猿阿伟1 天前
《声音的变形记:Web Audio API的实时特效法则》
开发语言·前端·php
Clownseven1 天前
Shell 脚本实战指南:内网 ARP 洪泛监控与飞书/邮件自动告警
网络·php·飞书
浪裡遊2 天前
React Hooks全面解析:从基础到高级的实用指南
开发语言·前端·javascript·react.js·node.js·ecmascript·php
ejinxian2 天前
PHP 超文本预处理器 发布 8.5 版本
开发语言·php
zorro_z2 天前
PHP语法基础篇(九):正则表达式
php
高压锅_12202 天前
思科与华为网络设备命令对比指南:从基础操作到高级配置
服务器·华为·php
SuperherRo2 天前
WEB攻防-文件包含&LFI&RFI&伪协议编码算法&无文件利用&黑白盒
php·文件包含·伪协议·lfi·无文件·黑白盒·rfi