Unix timestamp to days, hours, minutes

前端 未结 4 866
南方客
南方客 2021-01-07 06:22

So, I have a field in my users table named last_active which updates every time a user reloads a page.
It\'s stored in unix timestamp.

I would like

4条回答
  •  没有蜡笔的小新
    2021-01-07 06:56

    The simplest approach to this is to take the last_active timestamp, and the current timestamp with time(). Then subtract the last active from the current timestamp, and then you simply divide the result with the amount of seconds in a day to get difference in days, amount of seconds in an hour to get difference in hours and so on.

    This approach may be slightly inaccurate in some special cases (leap years, etc.) but it should suffice for your simpler usecase

提交回复
热议问题