P粉7879344762023-08-17 00:27:41
date_*()
函數和date()
是兩個不同的日期庫API的一部分,令人困惑的是。物件導向版本的date_*()
函數在一定程度上澄清了這一點,同時也是一個更強大的函式庫。例如:
$usersyear = 2001;
$usersmonth = 1;
$usersday = 1;
$takedate = new DateTime("$usersyear-$usersmonth-$usersday");
$today = new DateTime('today');
$diff = $today->diff($takedate);
var_dump($diff, $diff->y);
輸出:
object(DateInterval)#3 (10) { ["y"]=> int(22) ["m"]=> int(7) ["d"]=> int(15) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["invert"]=> int(1) ["days"]=> int(8262) ["from_string"]=> bool(false) } int(22)
參考:https://www.php.net/manual/en/book.datetime.php
#