• 技术文章 >后端开发 >php教程

    php 时间函数strtotime 使用详解

    不言不言2018-04-20 15:01:42原创2931
    这篇文章介绍的内容是关于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")));


    时间名词:
    年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函数详解

    以上就是php 时间函数strtotime 使用详解的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:strtotime php 详解
    上一篇:PHP生成指定位数验证码与可控干扰元素第二篇 下一篇:php文件下载 重命名
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• 用PHP来统计在线人数的四个方法详解• 怎么获取新浪微薄分享成功的返回值 • 40个迹象表明你还是PHP初学者 • ThinkPHP单字母函数收拾 • 为什么小弟我新装zend9,导入后,原站的中文字体变小了
    1/1

    PHP中文网