백엔드와 달리 작업 날짜를 포맷해야하기 때문에 호출 할 편리한 방법이 있으며 날짜 객체 프로토 타입에서 형식 메소드를 정의 할 수 있습니다. 다음과 같이 참조하십시오.
코드 사본은 다음과 같습니다.
// 날짜 및 시간 프로토 타입을위한 서식 메소드를 추가합니다
date.prototype.format = function (formatstr) {
var str = Formatstr;
var week = [ 'day', 'one', 'two', 'three', 'four', 'five', 'six'];
str = str.replace (/yyyy | yyyy/, this.getlyear ());
str = str.replace (/yy | yy/, (this.getyear () % 100)> 9?
var month = this.getmonth () + 1;
str = str.replace (/mm/, 월> 9?
str = str.replace (/m/g, 월);
str = str.replace (/w | w/g, Week [this.getDay ()];
str = str.replace (/dd | dd/, this.getDate ()> 9? this.getDate (). toString () : '0' + this.getDate ());
str = str.replace (/d | d/g, this.getDate ());
str = str.replace (/hh | hh/, this.gethours ()> 9? this.gethours (). toString () : '0' + this.gethours ());
str = str.replace (/h | h/g, this.gethours ());
str = str.replace (/mm/, this.getminutes ()> 9? this.getminutes (). toString () : '0' + this.getMinutes ());
str = str.replace (/m/g, this.getminutes ());
str = str.replace (/ss | ss/, this.getSeconds ()> 9? this.getSeconds (). toString () : '0' + this.getSeconds ());
str = str.replace (/s | s/g, this.getSeconds ());
Return str;
}
예를 들어 호출하는 것은 비교적 간단합니다.
코드 사본은 다음과 같습니다.
var d = 새로운 날짜 ();
var str = d.format ( "yyyy-mm-dd hh : mm : ss");
Console.log (str);