PHP: date “Yesterday”, “Today”

后端 未结 9 1814
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 10:20

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\         


        
9条回答
  •  失恋的感觉
    2020-12-09 11:07

    something like:
    
    $now = time();
    
    $last_midnight = $now - ($now % (24*60*60));
    
    if ($last_access >= $last_midnight)
    {
     print "Today";
    }    
    elseif ($last_access >= ($last_midnight-(24*60*60))
    {
     Print "Yesterday";
    }
    

提交回复
热议问题