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 -,
  • 相关阅读:
    模板方法模式
    策略模式
    代理模式
    单例模式
    工厂模式
    服务器负载过高问题分析
    支付宝APP支付开发- IOException : DerInputStream.getLength(): lengthTag=89, too big
    阿里云linux服务器挂载数据盘
    3.3.4.2选择特定行
    3.3.4.1选择所有数据
  • 原文地址:https://www.cnblogs.com/firstForEver/p/5239773.html
Copyright © 2011-2022 走看看