我在用这个answer from StackOverflow 作为使用PHP 5.2.2函数的基础
主要问题是human_time_diff() 并不总是返回天,也没有关于返回内容的参数。此函数只返回它们已注册的时间,无论是天、周、月还是年。我认为最可靠的解决方案是在PHP中完成这一切,真的:
$today_obj = new DateTime( date( \'Y-m-d\', strtotime( \'today\' ) ) ); // Get today\'s Date Object
$register_date = get_the_author_meta( \'user_registered\', get_current_user_id() ); // Grab the registration Date
$registered_obj = new DateTime( date( \'Y-m-d\', strtotime( $register_date ) ) ); // Get the registration Date Object
$interval_obj = $today_obj->diff( $registered_obj ); // Retrieve the difference Object
if( $interval_obj->days > 1 ) { // The most commonly hit condition at the top
echo __( "Registered {$interval_obj->days} days ago", "kiwi" );
} elseif( 0 == $interval_obj->days ) { // IF they registered today
echo __( \'Registered Today\', \'kiwi\' );
} elseif( 1 == $interval_obj->days ) { // IF they registered yesterday
echo __( \'Registered Yesterday\', \'kiwi\' );
} else { // The off-chance we have less than zero
echo __( \'Registered\', \'kiwi\' );
}
在这个答案中,我们使用
PHP DateTime Class 得到我们需要的东西。我删除了
i18n 函数和过滤器,我认为不需要它们,因为我们只处理整数,而不是特定的日期/时间。
如果代码注释需要更多说明,请在下面留下注释,我将对此进行详细说明。