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 小时前
【计算机网络】子网掩码与子网划分计算(含CIDR表示法)
服务器·笔记·计算机网络·php
cc_yy_zh5 小时前
学习使用kali抓包
服务器·学习·php
ao-weilai6 小时前
Linux网络编程:网络知识基础
linux·网络·php
clz131452111 小时前
设备反欺诈的四大支柱:从设备指纹到关联图谱
开发语言·php
PHP实战开发录15 小时前
PHP脚本手动能跑定时任务却失败
开发语言·php·开发
彧azz1 天前
图的存储结构详解:邻接矩阵的原理、实现与应用
开发语言·数据结构·学习·php
CRMEB系统商城1 天前
CRMEB标准版系统(Java)v3.1正式发布
java·spring·微信小程序·php·教育电商
hui-梦苑1 天前
[PHP]轻量主题函数WordPress 集成 KaTeX 数学公式渲染
开发语言·php·wordpress·katex
企查查数据服务1 天前
全军禁入下客商准入风控,关联图谱与穿透核查
大数据·开发语言·数据库·php
狗凯之家源码网1 天前
全开源 H5 棋牌对战系统修复优化与二次开发实测
开源·php·棋牌对战