Convert a Unix timestamp to time in JavaScript

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

    I'd think about using a library like momentjs.com, that makes this really simple:

    Based on a Unix timestamp:

    var timestamp = moment.unix(1293683278);
    console.log( timestamp.format("HH/mm/ss") );
    

    Based on a MySQL date string:

    var now = moment("2010-10-10 12:03:15");
    console.log( now.format("HH/mm/ss") );
    

提交回复
热议问题