php 时间函数strtotime 使用详解

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

语法
strtotime(time,now)

参数描述
time规定要解析的时间字符串。
now用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
     // #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")));
        
        // #11
        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')));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值