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

相关推荐
卤炖阑尾炎8 小时前
Linux firewalld 防火墙从入门到精通:原理与配置全解析
linux·运维·php
菩提小狗9 小时前
第23天:安全开发-PHP应用&后台模块&Session&Cookie&Toke_笔记|小迪安全2023-2024|web安全|渗透测试|
笔记·安全·php
天远云服9 小时前
天远企业司法认证API对接实战:PHP构建B2B供应链合规防火墙
大数据·开发语言·后端·node.js·php
zhangfeng113311 小时前
提示 R for Windows front-end 怎么被防火墙 阻止了 Rscript.exe` 和 `R.exe`区别
windows·r语言·php
微学AI11 小时前
内网穿透的应用-Plex 打造随身私人影院,用cpolar告别地狱限制。
开发语言·php
ZHOUPUYU12 小时前
我在PHP里学到的“套路”与“反套路” 设计模式与依赖注入
开发语言·php
JSON_L12 小时前
endroid/qr-code生成二维码报错
php·二维码
漏刻有时12 小时前
CentOS 不定时 OOM 根治方案:PHP-FPM 进程管控 + Swap 扩容 + 全维度监控
android·centos·php
CRMEB系统商城13 小时前
CRMEB标准版系统(PHP)v6.0公测版发布,商城主题市场上线~
java·开发语言·小程序·php
沐晨API14 小时前
最新API管理系统
php