문자열을 날짜 대상으로 변환하기 (각도를 바꾸어 코드를 쓰기)

1808 단어 Patternyyyyyear

    /** 
     *  . 
     */  
    var GlobalDatePattern = [  
        {   
          pattern: "yyyy-MM-dd HH:mm:ss",   
          fix: { year: 0, month: 1, day: 2, hour: 3, minute: 4, second: 5 }   
        },   
        {   
          pattern: "yyyy/MM/dd HH:mm:ss",   
          fix: { year: 0, month: 2, day: 3, hour: 3, minute: 4, second: 5 }   
        },   
        {   
          pattern: "MM-dd-yyyy HH:mm:ss",   
          fix: { year: 2, month: 0, day: 1, hour: 3, minute: 4, second: 5 }   
        }  
        //  ...  200  
    ];  
      
    /** 
     *  . 
     * @param strDate   
     * @param pattern   
     * @return   
     */  
    function parseDate(strDate, pattern) {  
      var datePattern;  
      
      //   
      for (var i = 0; i < GlobalDatePattern.length; i++) {  
        if (pattern == GlobalDatePattern[i].pattern) {  
          datePattern = GlobalDatePattern[i];  
          break;  
        }  
      }  
      
      // ...  500 
        
      //    
      var aryDate = strDate.match(/\d+/g);  
      var date = new Date();  
        
      // ... 100   

      date.setFullYear(aryDate[datePattern.fix.year]);  
      date.setMonth(aryDate[datePattern.fix.month] - 1);  
      date.setDate(aryDate[datePattern.fix.day]);  
      date.setHours(aryDate[datePattern.fix.hour]);  
      date.setMinutes(aryDate[datePattern.fix.minute]);  
      date.setSeconds(aryDate[datePattern.fix.second]);  
      
      return date;  
    }  

좋은 웹페이지 즐겨찾기