加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2021-06-03 19:27:51 所属栏目:PHP教程 来源:互联网
导读: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(

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。

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读