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-11-17 10:05:53

    mongoDB 修改密码

    mongodb的用户信息是存放在system.users表中的,修改密码不能直接更新表数据,这样的话,存到表里的密码是明文的,这就不对了。

  • 2020-11-17 10:13:16

    Vue.observable()进行状态管理

    随着组件的细化,就会遇到多组件状态共享的情况, Vuex当然可以解决这类问题,不过就像 Vuex官方文档所说的,如果应用不够大,为避免代码繁琐冗余,最好不要使用它,今天我们介绍的是 vue.js 2.6 新增加的 Observable API ,通过使用这个 api 我们可以应对一些简单的跨组件数据状态共享的情况。

  • 2020-11-17 10:17:18

    MongoDB日志文件查看

    默认情况下,MongoDB在此路径/var/log/mongodb/mongodb.log创建日志文件,如果找不到该日志文件,请检查MongoDB配置文件。

  • 2020-11-17 11:57:16

    app抓包无数据

    我们经常在wifi设置中 设置代理到我们的pc http代理软件上,多数情况下,此时我们开启的app流量都可以在代理软件上看到,比如charles , fiddler等等。 但是细心的人会发现 某些大厂的app 某些请求 在这些 http代理软件上就是抓不到, 给人的感觉就是 流量没从代理软件走一样。

  • 2020-11-17 11:57:55

    app抓不到包,解决很简单

    1.手机安装virtualXpost 并激活xpost 框架,如有问题自行百度。 2.安装justTrustMe,然后再virtualXpost中添加此模块 3.安装手机抓包神器packet capture 4.在virtualXpost中运行app,并打开packet capture抓包就行

  • 2020-11-17 16:50:16

    JS常见加密混淆方式

    目录 前端js常见混淆加密保护方式 eval方法等字符串参数 emscripten WebAssembly js混淆实现 JSFuck AAEncode JJEncode 代码压缩 变量名混淆 字符串混淆 自我保护,比如卡死浏览器 控制流平坦化 僵尸代码注入 对象键名替换 禁用控制台输出 调试保护,比如无限Debug,定时Debug 域名锁定