module.exports = class iDate {
constructor(_Date) {
this.Date = _Date;
this.YYYY = _Date.getFullYear().toString();
this.MM = pad(_Date.getMonth()+1, 2);
this.DD = pad(_Date.getDate(), 2);
this.hh = pad(_Date.getHours(), 2);
this.mm = pad(_Date.getMinutes(), 2);
this.ss = pad(_Date.getSeconds(), 2);
this.ms = pad(_Date.getMilliseconds(), 3);
}
format(_format) {
return _format
.replace("YYYY", this.YYYY)
.replace("MM", this.MM)
.replace("DD", this.DD)
.replace("hh", this.hh)
.replace("mm", this.mm)
.replace("ss", this.ss)
.replace("ms", this.ms);
}
}
function pad(number, length) {
var str = number.toString();
while (str.length < length) {
str = "0" + str;
}
return str;
}
var iDate = require("./modules/iDate.js");
var date = new iDate(new Date());
savedDate = date.format("YYYY-MM-DD hh:mm:ss.ms");
대충 날짜를 문자열로 바꿔주는 걸 만들어봤는데
클래스 쓰는게 좀 복잡하네요 ㅋㅋ 그래도 지금만든건 두고두고 쓸듯