xx time ago function doesn't work

前端 未结 1 1560
独厮守ぢ
独厮守ぢ 2020-12-22 14:29

I am trying to display \"{number} {unit-of-time} ago\" in my chat. However, when I\'m expecting something like \"2 minutes ago\", I see \"45 years\" instead.

Nobody

1条回答
  •  礼貌的吻别
    2020-12-22 15:02

    1. You have to fetch the date:

      $tm = mysql_query("SELECT timestamp AS t FROM logs ORDER by id ASC")->fetch_assoc()['t']; //obviously, check the size before you fetch

    2. You probably want to use strtotime() so for instance:

      $dif = $cur_tm-strtotime($tm);

    3. The $dif will be in milliseconds.

    4. What are you doing with the loops and the arrays? Too confusing.

    5. WHY DO PEOPLE KEEP USING mysql_!!!

    0 讨论(0)
提交回复
热议问题