개발

mysql date값 파싱 본문

JavaScript

mysql date값 파싱

Dev.hs 2019. 6. 21. 10:08

ajax를 통해 넘어온 mysql result.regDate값 파싱

 

 

 

let date = new Date(); 
let year = date.getFullYear();  
let month = new String(date.getMonth()+1);  
let day = new String(date.getDate());  
let week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']; 
let dayOfWeek = week[date.getDay()]; 
let selDate = year + "-" + month + "-" + day; 
let realPage = 1;





Date.prototype.format = function(f) {

    if (!this.valueOf()) return " "; 
  
    const weekName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"]; 
    let d = this; 
    let h; 
      
    return f.replace(/(yyyy|yy|MM|dd|E|hh|mm|ss|a\/p)/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 "dd": return d.getDate().zf(2); 
            case "E": return weekName[d.getDay()]; 
            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); 
            case "a/p": return d.getHours() < 12 ? "오전" : "오후"; 
            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);};

 

 

 

 

 

 

 

'JavaScript' 카테고리의 다른 글

jquery ajax async에따른 실행순서  (0) 2021.01.17
Comments