php strtotime常见用法

strtotime() 函数在 PHP 中用于将日期时间字符串转换为 UNIX 时间戳,它可以解析包括英文描述的日期时间字符串。以下是 strtotime() 函数的一些常见用法:

  1. 日期时间字符串转换为 UNIX 时间戳:

    $timestamp = strtotime('2024-04-20 10:30:00');

  2. 相对时间转换为 UNIX 时间戳:

    // 当前时间的前一天
    $timestamp = strtotime('-1 day');
    // 当前时间的后一周
    $timestamp = strtotime('+1 week');

  3. 解析英文日期时间描述:

    // 下周五
    $timestamp = strtotime('next Friday');
    // 2小时后
    $timestamp = strtotime('+2 hours');
    // 上个月的第一天
    $timestamp = strtotime('first day of last month');
  4. 解析相对日期时间描述:

    // 3天后的下午3点
    $timestamp = strtotime('3 days 15:00');
    // 明年的1月1日
    $timestamp = strtotime('next year January 1');
  5. 指定基准时间进行解析:

    // 在指定时间基础上加上3天
    $timestamp = strtotime('+3 days', $baseTimestamp);

这些都是 strtotime() 函数常见的用法,可以根据具体需求选择合适的方式来进行日期时间字符串的解析。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Annuo、

您的青睐将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值