본문으로 바로가기
반응형
new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), new Date().getHours(), new Date().getMinutes(), new Date().getSeconds())).toISOString().replace("T", " ").replace(".", " ").slice(0, 19);

혹은

 

var date = new Date();
var date_format_str = date.getFullYear().toString() + "-" + ((date.getMonth() + 1).toString().length == 2 ? (date.getMonth() + 1).toString() : "0" + (date.getMonth() + 1).toString()) + "-" + (date.getDate().toString().length == 2 ? date.getDate().toString() : "0" + date.getDate().toString()) + " " + (date.getHours().toString().length == 2 ? date.getHours().toString() : "0" + date.getHours().toString()) + ":" + ((parseInt(date.getMinutes() / 5) * 5).toString().length == 2 ? (parseInt(date.getMinutes() / 5) * 5).toString() : "0" + (parseInt(date.getMinutes() / 5) * 5).toString()) + ":00";
console.log(date_format_str);

 

반응형

'Frontend > Javascript' 카테고리의 다른 글

Browser OS Check By Easy Version  (0) 2020.05.22
비밀번호 검사  (0) 2020.05.19
JS Redux  (0) 2020.05.05
Javascript Key Trigger Event  (0) 2020.04.24
IE 팝업 액세스 거부  (0) 2020.02.20