PHP: date “Yesterday”, “Today”
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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? 回答1: 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