设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP如何从字符串中获取时间日期

发布时间:2021-06-02 04:39 所属栏目:121 来源:互联网
导读:参数说明: time 为字符串形式的日期时间; now 规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 返回值:执行成功则返回时间戳,否则返回 false

echo strtotime("now"), "<br />";

echo strtotime("10 September 2000"), "<br />";

echo strtotime("+1 day"), "<br />";

echo strtotime("+1 week"), "<br />";

echo strtotime("+1 week 2 days 4 hours 2 seconds"), "<br />";

echo strtotime("next Thursday"), "<br />";

echo strtotime("last Monday"), "<br />";

?>

执行以上程序打印出来的结果类似:

1572597225 968515200 1572683625 1573202025 1573389227 1573056000 1572192000

日期的加减运算 有时我们需要在一个日期上加减一定的时间间隔。可以使用 strtotime() 来计算一些日期时间间隔。示例如下:

<?php

$start = 'last Monday';

$interval = strtotime("$start + 4 days");

echo "现在\$interval 表示上周的" . date('l',$interval);

?>

执行以上程序的输出结果为:

现在 $interval 表示上周的 Friday。

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读