您的位置:首页 > 编程语言 > PHP开发

php中DateTime、diff

2016-03-03 19:18 716 查看
  

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

$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $january->diff($february);

// %a will output the total number of days.
echo $interval->format('%R%a total days'). '<br/>';// +31 total days

// While %d will only output the number of days not already covered by the
// month.
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 (%).
format
character
DescriptionExample values
%Literal %%
YYears, numeric, at least 2 digits with leading 001, 03
yYears, numeric1, 3
MMonths, numeric, at least 2 digits with leading 001, 03, 12
mMonths, numeric1, 3, 12
DDays, numeric, at least 2 digits with leading 001, 03, 31
dDays, numeric1, 3, 31
aTotal number of days as a result of a DateTime::diff() or (unknown)otherwise4, 18, 8123
HHours, numeric, at least 2 digits with leading 001, 03, 23
hHours, numeric1, 3, 23
IMinutes, numeric, at least 2 digits with leading 001, 03, 59
iMinutes, numeric1, 3, 59
SSeconds, numeric, at least 2 digits with leading 001, 03, 57
sSeconds, numeric1, 3, 57
RSign "-" when negative, "+" when positive-, +
rSign "-" when negative, empty when positive-,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: