Convert a Unix timestamp to time in JavaScript

前端 未结 29 2175
渐次进展
渐次进展 2020-11-21 04:57

I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it?

For example, in HH/MM/

29条回答
  •  滥情空心
    2020-11-21 05:33

    If you want to convert Unix time duration to real hours, minutes, and seconds, you could use the following code:

    var hours = Math.floor(timestamp / 60 / 60);
    var minutes = Math.floor((timestamp - hours * 60 * 60) / 60);
    var seconds = Math.floor(timestamp - hours * 60 * 60 - minutes * 60 );
    var duration = hours + ':' + minutes + ':' + seconds;
    

提交回复
热议问题