본문 바로가기
JAVASCRIPT

DateTime의 형식 JSON 데이터 날짜,시간 형식으로 보여주기 예제

by Hwoarang757 2015. 3. 5.

 

$(document).ready(function () {

            var test = GetDateString("/Date(1425518216500)/");

            alert(test);

}

 

 

        function GetDateString(jsonDate) {

            var year, month, day, hour, minute, second , returnValue  , date ,replaceStr

 

            replaceStr = jsonDate.replace(/\D/g, "");

            date = new Date(parseInt(replaceStr));

 

            year = date.getFullYear();

            month = Pad(date.getMonth());

            day = Pad(date.getDate());

            hour = Pad(date.getHours());

            minute = Pad(date.getMinutes());

            second = Pad(date.getSeconds());

 

            returnValue = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

            return returnValue;

        }

 

        function Pad(num) {

            num = "0" + num;

            return num.slice(-2);

        }