<?php
// strtotime 是 PHP 中用于将英文文本日期时间描述解析为 Unix 时间戳的函数。
// 示例 1: 将自然语言描述的时间转换为 Unix 时间戳
echo strtotime("now"), "\n"; // 输出当前时间的时间戳
// 示例 2: 将特定日期和时间转换为 Unix 时间戳
echo strtotime("10 September 2023"), "\n"; // 输出 2023 年 9 月 10 日的时间戳
// 示例 3: 使用相对格式
echo strtotime("+1 day"), "\n"; // 输出明天的时间戳
echo strtotime("+1 week"), "\n"; // 输出一周后的时间戳
echo strtotime("+1 week 2 days 4 hours"), "\n"; // 输出一周两天四小时后的时间戳
echo strtotime("next Sunday"), "\n"; // 输出下一个周日的时间戳
echo strtotime("last Monday"), "\n"; // 输出上一个周一的时间戳
// 示例 4: 结合 date() 函数使用,将 Unix 时间戳转换为可读的日期格式
$date = date("Y-m-d H:i:s", strtotime("tomorrow"));
echo $date, "\n"; // 输出明天的日期和时间,格式为 YYYY-MM-DD HH:MM:SS
?>
上一篇:php 字符串替换
下一篇:php array_push
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站