Convert a Unix timestamp to time in JavaScript

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

    function getTIMESTAMP() {
      var date = new Date();
      var year = date.getFullYear();
      var month = ("0" + (date.getMonth() + 1)).substr(-2);
      var day = ("0" + date.getDate()).substr(-2);
      var hour = ("0" + date.getHours()).substr(-2);
      var minutes = ("0" + date.getMinutes()).substr(-2);
      var seconds = ("0" + date.getSeconds()).substr(-2);
    
      return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
    }
    
    //2016-01-14 02:40:01
    

提交回复
热议问题