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

相关推荐
t1987512810 小时前
使用深度神经网络解决无线网络资源分配问题的MATLAB实现
matlab·php·dnn
m0_4592524611 小时前
fastadmin动态渲染统计信息
开发语言·前端·javascript·php
AI成长日志11 小时前
【实用工具教程】Linux常用命令速查与实战场景:文件操作、进程管理与网络调试高频命令解析
linux·php
ccchen88811 小时前
适配帝国CMS 8.0:全新帝国CMS免登录采集发布插件
经验分享·爬虫·php·帝国cms自动采集发布插件·帝国cms8.0·帝国cms自动采集插件·帝国cms采集发布模块
vx-程序开发13 小时前
springboot在线装修管理系统-计算机毕业设计源码56278
java·c语言·spring boot·python·spring·django·php
幽络源小助理13 小时前
网页软件库源码(带1153条资源)-含详细搭建教程
php
博语小屋16 小时前
多路转接select、poll
开发语言·网络·c++·php
xuansec16 小时前
PHP 反序列化漏洞学习笔记(CTF向总结)
笔记·学习·php
liuxin_072516 小时前
Composer 安装
php·composer
共享家952718 小时前
Java入门( 异常 )
java·开发语言·php