zoukankan      html  css  js  c++  java
  • 求两个时间的日期差-部分

    方法一

    1 $date1 = mktime(0,0,0,2,5,2007); // mktime,对时间格式要求严格,返回一个unix时间戳
    2 $date2 = mktime(0,0,0,3,6,2007);
    3 echo ($date2 - $date1)/(24*3600);

    方法二

     1 echo (strtotime('20070316')-strtotime('20070306'))/(24*3600); // strtotime,将一个英式日期戳转换成一个unix时间戳,只要格式符合日期格式即可 

    注意点:月份和天的日期都不能省去十位的零,否则会出现不以明之的错误

    1 echo date('Y-m-d', strtotime('20050206')),'<br>'; // 2005-02-06
    2 echo date('Y-m-d', strtotime('2005206')),'<br>'; // 2005-07-25
    3 echo date('Y-m-d', strtotime('200526')),'<br>'; // 2016-11-16

    方法三

     1 echo abs(strtotime(“2007-2-1 2 ″)-strtotime(“2007-3-1″))/60/60/24 计算时间差 

    strtotime的用法:

    1 echo strtotime("now"), '<br>';
    2 echo strtotime("10 September 2000"), '<br>';
    3 echo strtotime("+1 day"), '<br>';
    4 echo strtotime("+1 week"), '<br>';
    5 echo strtotime("+1 week 2 days 4 hours 2 seconds"), '<br>';
    6 echo strtotime("next Thursday"), '<br>';
    7 echo strtotime("last Monday"), '<br>';
    8 // 返回的都是unix时间戳
    相应的结果:
    1479143620
    968515200
    1479230020
    1479748420
    1479935622
    1479312000
    1479052800
  • 相关阅读:
    Mac版sublime text右键open in browser 不能识别中文名解决办法
    python 内置函数
    python 迭代器 生成器 列表推导式和生成器表达式
    python 闭包
    python 练习题
    python 打印扑克牌练习题
    python 函数 可变数据类型默认值
    python min() ,max()
    python 九九乘法表
    函数的进阶
  • 原文地址:https://www.cnblogs.com/online-link/p/6063437.html
Copyright © 2011-2022 走看看