此外,如果您想处理天数、小时数等,您可以使用DateTime 和DateInterval 对象:
global $post;
$utc = new DateTimeZone( \'UTC\' );
$post_date = new DateTime( $post->post_date_gmt, $utc );
$now = new DateTime( \'now\', $utc );
$diff = $post_date->diff( $now );
$diff
现在是
DateInterval
具有以下属性的对象:
object(DateInterval)#4 (8) {
["y"]=>
int(0)
["m"]=>
int(2)
["d"]=>
int(16)
["h"]=>
int(19)
["i"]=>
int(29)
["s"]=>
int(59)
["invert"]=>
int(0)
["days"]=>
int(75)
}