HTML
<div id="result"></div>
js
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear(),
hour = d.getHours(),
min = d.getMinutes(),
sec = d.getSeconds();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-') + ' ' + [hour,min,sec].join(':');
}
var dateText = "/Date(1519794794410)/";
var myDate = new Date(dateText.match(/\d+/) * 1);
document.getElementById('result').innerHTML = formatDate(myDate);
jsfiddle demo link : https://jsfiddle.net/d18ggjhL/6/
참고
javascript format - http://jsfiddle.net/2Frm3/1561/
convert json date - https://goo.gl/qmgVY5
'js' 카테고리의 다른 글
[javascript] ++ 연산자 (0) | 2019.01.25 |
---|---|
[javascript] 나누기, 나머지, 몫 구하기 (0) | 2018.02.22 |
[javascript] Uncaught TypeError: is not a function (0) | 2018.01.10 |
[jquery] how to get custom attribute value (0) | 2017.12.29 |
[javascript] get parameters to object (0) | 2017.12.28 |