PHP: date “Yesterday”, “Today”

后端 未结 9 1816
爱一瞬间的悲伤
爱一瞬间的悲伤 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:18

    I would find the timestap for last midnight and the one before it, if $last_access is between the two timestamps, then display yesterday, anything greater than last midnight's timestamp would be today...

    I believe that would be the quicker than doing date arithmetic.

    Actually, I just tested this code and it seems to work great:

    = strtotime("today"))
            echo "Today";
        else if ($last_access >= strtotime("yesterday"))
            echo "Yesterday";
    ?>
    

提交回复
热议问题