所以我有这样的代码,负责显示多少天前的用户加入了一个网站:变化数月/年
<?php echo sprintf(__('Joined %s ago','PricerrTheme'),$joined); ?>
然而,它现在显示的是,例如“ 加入150天前。“
我想让它显示,例如,什么” 加入5个月之前。“
这应该是一个小编辑到代码我张贴以上。谁能帮忙?
所以我有这样的代码,负责显示多少天前的用户加入了一个网站:变化数月/年
<?php echo sprintf(__('Joined %s ago','PricerrTheme'),$joined); ?>
然而,它现在显示的是,例如“ 加入150天前。“
我想让它显示,例如,什么” 加入5个月之前。“
这应该是一个小编辑到代码我张贴以上。谁能帮忙?
您可以使用DateTime
(look here)PHP类,让这样的代码:
$interval = new DateInterval('P'.$joined.'D');
$days = $interval->format('%d'); // This will convert in days
$months = $interval->format('%m'); // This will convert in months
$years = $interval->format('%y'); // This will convert in years
要确定您需要哪种的这些,你可以使用数学条件,如:
if($joined/30 > 0) {
if($joined/30 > 12) {
// Show years
}
// Show months
} else {
// Show days
}
请带看看这个https://github.com/briannesbitt/Carbon –
感谢您的回复。但是这并不能帮助我。我不明白:( – Overloard