本文介绍了PHP:date“Yesterday”,“Today”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个功能显示最新的活动,它从数据库中获取unix格式的时间戳,然后用这一行回显: date(G:i:sj M -Y,$ last_access)
现在我想将日期(j M -Y)替换为昨天,今天如果最近的活动在今天之内,并且与昨天相同。
如何我可以这样做吗?
解决方案
function get_day_name($ timestamp){
$ date = date('d / m / Y',$ timestamp);
if($ date == date('d / m / Y')){
$ date ='今天'
}
else if($ date == date('d / m / Y',now() - (24 * 60 * 60))){
$ date ='Yesterday' ;
}
return $ date;
}
打印日期('G:i:s',$ last_access)''.get_day_name($ last_access);
I have a little function that shows latest activity, it grab timestamp in unix format from the db, and then it echo out with this line:
date("G:i:s j M -Y", $last_access)
Now i would like to replace the date (j M -Y) to Yesterday, and Today if the latest activity was within today, and same goes with Yesterday.
How can i do this?
解决方案
function get_day_name($timestamp) {
$date = date('d/m/Y', $timestamp);
if($date == date('d/m/Y')) {
$date = 'Today';
}
else if($date == date('d/m/Y',now() - (24 * 60 * 60))) {
$date = 'Yesterday';
}
return $date;
}
print date('G:i:s', $last_access).' '.get_day_name($last_access);
这篇关于PHP:date“Yesterday”,“Today”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!