Convert a Unix timestamp to time in JavaScript

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

    Use:

    var s = new Date(1504095567183).toLocaleDateString("en-US")
    console.log(s)
    // expected output "8/30/2017"  
    

    and for time:

    var s = new Date(1504095567183).toLocaleTimeString("en-US")
    console.log(s)
    // expected output "3:19:27 PM"

    see Date.prototype.toLocaleDateString()

提交回复
热议问题