Timestamp to time

I encountered a problem today. After using ajax to obtain data, the data was combined and inserted into the page, but one of the time fields was displayed in the 1488850813000 format after insertion, and what I thought was 2017-01-01 12:12 :12 format, I scoured the Internet and found that someone has solved this problem, so I will record it here.

Premise: Introduce JQuery files

 function getMyDate(str){  
            var oDate = new Date(str),  
            oYear = oDate.getFullYear(),  
            oMonth = oDate.getMonth()+1,  
            oDay = oDate.getDate(),  
            oHour = oDate.getHours(),  
            oMin = oDate.getMinutes(),  
            oSen = oDate.getSeconds(),  
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间  
            return oTime;  
        }; 
        //补0操作
      function getzf(num){  
          if(parseInt(num) < 10){  
              num = '0'+num;  
          }  
          return num;  
      }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

How to use: 
var data = getMyDate(1488850813000 );

The result is: 2017/3/7 9:40:13

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324688880&siteId=291194637