Hướng dẫn php dateinterval pt1h
(PHP 5 >= 5.3.0, PHP 7, PHP 8) DateInterval::__construct — Creates a new DateInterval object Descriptionpublic DateInterval::__construct(string Parametersduration
An interval specification. The format starts with the letter duration Period Designators
Here are some simple examples. Two days is
The specification can
also be represented as a date time. A sample of one year and four days would be These formats are based on the » ISO 8601 duration specification. Errors/Exceptions Throws an
Exception when the Changelog
ExamplesExample #1 Constructing and using DateInterval objects
The above example will output: Example #2 DateInterval example
= new DateInterval('P1W2D'); Output of the above example in PHP 8.2: object(DateInterval)#1 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(9) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> bool(false) ["from_string"]=> bool(false) } Output of the above example in PHP 8: object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(9) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } Output of the above example in PHP 7: object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } See Also
owen at beliefs.com ¶ 9 years ago
buvinghausen at gmail dot com ¶ 10 years ago
Hernanibus ¶ 4 years ago
kevinpeno at gmail dot com ¶ 11 years ago
daniellehr at gmx dot de ¶ 10 years ago
kuzb ¶ 11 years ago
jawzx01 at gmail dot com ¶ 10 years ago
admin at torntech dot com ¶ 7 years ago
userexamplecom at mailinator dot com ¶ 6 years ago
lsloan-php dot net at umich dot edu ¶ 6 years ago
Anonymous ¶ 1 year ago
= (new DateTime('now'))->add(new DateInterval("PT1H"));var_dump($plusOneHour);?>
grzeniufication ¶ 2 years ago
DateInterval extends \DateInterval sloanlance+php.net gmail com ¶ 4 years ago
Ray.Paseur sometimes uses Gmail ¶ 6 years ago
|