Convert a Unix timestamp to time in JavaScript

前端 未结 29 2178
渐次进展
渐次进展 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:28

    Shortest

    (new Date(ts*1000)+'').slice(16,24)
    

    let ts = 1549312452;
    let time = (new Date(ts*1000)+'').slice(16,24);
    
    console.log(time);

提交回复
热议问题