zoukankan      html  css  js  c++  java
  • php中DateTime、diff

      

    手册地址:http://php.net/manual/en/dateinterval.format.php

     1 $january = new DateTime('2010-01-01');
     2 $february = new DateTime('2010-02-01');
     3 $interval = $january->diff($february);
     4 
     5 // %a will output the total number of days.
     6 echo $interval->format('%R%a total days'). '<br/>';// +31 total days
     7 
     8 // While %d will only output the number of days not already covered by the
     9 // month.
    10 echo $interval->format('%m month, %d days');// 1 month, 0 days

    format格式化参数:

    
    
    The following characters are recognized in the format parameter string. Each format character must be prefixed by a percent sign (%).
    formatcharacterDescriptionExample values
    % Literal % %
    Y Years, numeric, at least 2 digits with leading 0 0103
    y Years, numeric 13
    M Months, numeric, at least 2 digits with leading 0 010312
    m Months, numeric 1312
    D Days, numeric, at least 2 digits with leading 0 010331
    d Days, numeric 1331
    a Total number of days as a result of a DateTime::diff() or (unknown)otherwise 4188123
    H Hours, numeric, at least 2 digits with leading 0 010323
    h Hours, numeric 1323
    I Minutes, numeric, at least 2 digits with leading 0 010359
    i Minutes, numeric 1359
    S Seconds, numeric, at least 2 digits with leading 0 010357
    s Seconds, numeric 1357
    R Sign "-" when negative, "+" when positive -+
    r Sign "-" when negative, empty when positive -,
  • 相关阅读:
    jvm的方法栈在干什么
    时间段交集查询
    linux 设置静态ip配置
    elk 学习
    内网穿透 https:natapp.cn
    mysql当前时间,日期转换,日期格式化
    swaggerui api.docs
    linux java -jar 后台进程
    druid 数据源 sql控制台输出
    spring pointcut 表达式
  • 原文地址:https://www.cnblogs.com/firstForEver/p/5239773.html
Copyright © 2011-2022 走看看