//DATE FORMATTING
//new Date().format("yyyy-MM-dd HH:mm")
Date.prototype.format = function(f) {
if (!this.valueOf()) return " ";
var d = this;
return f.replace(/(yyyy|yy|MM|dd|hh|mm|ss)/gi, function($1) {
switch ($1) {
case "yyyy": return d.getFullYear();
case "yy": return (d.getFullYear() % 1000).zf(2);
case "MM": return (d.getMonth() + 1).zf(2);
case "MM": return (d.getMonth() + 1).zf(2);
case "dd": return d.getDate().zf(2);
case "HH": return d.getHours().zf(2);
case "hh": return ((h = d.getHours() % 12) ? h : 12).zf(2);
case "mm": return d.getMinutes().zf(2);
case "ss": return d.getSeconds().zf(2);
default: return $1;
}
});
};
String.prototype.string = function(len){var s = '', i = 0; while (i++ < len) { s += this; } return s;};
String.prototype.zf = function(len){return "0".string(len - this.length) + this;};
Number.prototype.zf = function(len){return this.toString().zf(len);};
'웹스토리 > Jquery,Js' 카테고리의 다른 글
data attrbute를 이용한 데이터 바인딩 (0) | 2019.04.24 |
---|---|
OriginalAjax 변경 처리 (0) | 2019.04.24 |
jquery ajax 공통적으로 로딩 이미지 처리 (0) | 2018.02.28 |
자바스크립트 다국어 처리 (0) | 2018.02.28 |
JS 라이브러리 사이트 (0) | 2017.05.31 |