php 时间函数strtotime 使用详解

2018-12-08 11:44:26
这篇文章介绍的内容是关于php 时间函数strtotime 使用详解 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下


定义和用法 strtotime() 
strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。

语法 
strtotime(time,now)

参数描述
time规定要解析的时间字符串。
now用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
  • 说明 
    该函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数,则用系统当前时间。 
    该函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_timezone_get() 函数页面中有说明。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

// #1

echo strtotime("now");  // 获取当前时间戳

echo date('Y-m-d H:i:s', strtotime("now"));

// #2

echo strtotime("2015-06-11 10:11:00");  // 获取指定的时间戳

echo date('Y-m-d H:i:s', strtotime("2015-06-11 10:11:00"));

// #3

echo strtotime("3 October 2005");   // 获取指定的时间戳[等同于strtotime("2005-10-03")]

echo date('Y-m-d H:i:s', strtotime("3 October 2005"));

// #4

echo strtotime("+5 hours"); // 当前时间加五个小时 [对比#1]

echo date('Y-m-d H:i:s', strtotime("+5 hours"));

// #5

echo strtotime("+1 day");   // 当前时间加1天 [对比#1]

echo date('Y-m-d H:i:s', strtotime("+1 day"));

// #6

echo strtotime("+2 days");  // 当前时间加多天 名词变复数 [对比#1]

echo date('Y-m-d H:i:s', strtotime("+2 days"));

// #7

echo strtotime("+1 week 3 days 7 hours 5 seconds"); // 当前时间加 1周 3天 7小时 5秒 [对比#1]

echo date('Y-m-d H:i:s', strtotime("+1 week 3 days 7 hours 5 seconds"));

// #8

echo strtotime("next Monday");  // 当前时间下一个周一

echo date('Y-m-d H:i:s', strtotime("next Monday"));

// #9

echo strtotime("last Sunday");  // 当前时间前一个周日

echo date('Y-m-d H:i:s', strtotime("last Sunday"));

// #10

echo strtotime("-1 day",strtotime("2018-07-01 10:11:00"));  // 给定时间 减去一天

echo date('Y-m-d H:i:s', strtotime("-1 day",strtotime("2018-07-01 10:11:00")));


时间名词: 
年year 复数years 
月month 复数months 
周week 复数weeks 
日day 复数days 
时hour 复数hours 
分second 复数seconds 
秒minute 复数minutes 
上一个last 
下一个next 
一月January 
二月February 
三月March 
四月April 
五月May 
六月June 
七月July 
八月August 
九月September 
十月October 
十一月November 
十二月December

相关推荐:

php 使用strtotime获取上个月、下个月、本月的日期代码实例

php中strtotime函数详解


  • 2020-12-17 10:55:48

    html5 video p2p research

    节约带宽,减少缓冲时间,提升服务质量,处理峰值流量, 视频观看的人越多,播放越流畅。

  • 2020-12-17 10:57:34

    使用 MediaSource 搭建流式播放器

    Media Source Extensions(媒体源扩展)大大地扩展了浏览器的媒体播放功能,提供允许JavaScript 生成媒体流。这可以用于自适应流(adaptive streaming,也是我毕设的研究方向)及随时间变化的视频直播流(live streaming)等应用场景。

  • 2020-12-17 11:00:37

    H5流式播放(FMP4转封装与mediaSource)

    W3C上有明确关于mediaSource 扩展接口的文档。mediaSource 扩展文档中是这么定义的, 它允许JS脚本动态构建媒体流用于和,允许JS传送媒体块到H5媒体元素。这种接口的应用可以让h5播放器实现持续添加数据进行播放。做as的朋友都知道as中的appendBytes方法,一种添加二进制数据进行播放的方式。这两种接口在概念上是类似的。只是里面的定义和对媒体文件的要求有所不同。对于mediaSource扩展接口我只介绍我们主要应用的几个。

  • 2020-12-18 17:15:29

    coTurn stun服务器搭建,禁用turn

    https://github.com/coturn/coturn 在这里git clone 下来然后编译安装,一切默认即可。编译后,也可以不用安装。在编译目录下bin文件夹下有turnserver turnutils_stunclient turnutils_uclient 这三个等一下会用到的软件。

  • 2020-12-18 17:26:25

    coturn配置文件详细解释

    Coturn 是webrtc,p2p视频通话必不少的,主要包含2个主要功能stun服务, turn服务 Coturn 的githup地址为 https://github.com/coturn/coturn/

  • 2020-12-21 06:26:16

    为UIView添加点击事件

    最近经常碰到要将UIImageView和UILabel看成整体的情况,我于是就将他俩用UIView包起来,那么怎么给一个UIView添加点击事件,可以这么实现: