Developer/Javascript
Date format 변경 함수
슈퍼두치
2017. 12. 26. 14:20
/** /** * 원하는 포맷 반환 * * 1: yyyy/MM/dd hh:mm:ss * 2: yyyy/MM/dd * 3: yyyy/MM/ * */ function getFormatDate(date, want){ var year = date.getFullYear(); // Year var month = (1 + date.getMonth()); // Month month = month >= 10 ? month : '0' + month; // Month 두자리로 저장 var day = date.getDate(); // Day day = day >= 10 ? day : '0' + day; // Day 두자리로 저장 var hour = date.getHours(); // Hour hour = hour >= 10 ? hour : '0' + hour; // Hour 두자리로 저장 var min = date.getMinutes(); // Minute min = min >= 10 ? min : '0' + min; // Minute 두자리로 저장 var sec = date.getSeconds(); // Second sec = sec >= 10 ? sec : '0' + sec; // Second 두자리로 저장 var result = ''; switch(want) { case "1" : result = year + '/' + month + '/' + day + ' ' + hour + ':' + min + ':' + sec; break; case "2" : result = year + '/' + month + '/' + day; break; case "3" : result = year + '/' + month; break; } return result; }