Js 확장 시간 포맷 가능, 사용자 정의 시간 형식
1665 단어 자바 script
/* http://www.naoqiu.com*/
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"H+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
다음은 두 개의 자정 함 수 를 추가 합 니 다. 하 나 는 시간 변수 인지 아 닌 지 를 판단 하 는 것 이 고 다른 하 나 는 문자열 전환 시간 변수 입 니 다.코드 는 다음 과 같 습 니 다:
/* http://power.76741.com*/
function isDate(date) {
date = date == undefined ? "" : date.toString().toDate();
return new Date(date) != "Invalid Date" && new Date(date) != "NaN";
}
/* */
String.prototype.toDate = function () {
return new Date(this.replace(RegExp("-", "g"), "/"));
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Thymeleaf 의 일반 양식 제출 과 AJAX 제출텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.