Javascript date formatting sample share


 
 Util.parseToDate = function(ms){   
        var date = (new Date(parseInt(ms))); 
        return formatDate(date,"yyyy-MM-dd mm:hh");  
 };  
/** 
 *  Format date  
 * <code> 
 * yyyy------- years  
 * MM--------- month  
 * dd--------- day  
 * hh--------- when  
 * mm--------- points  
 *  Such as: Util.formatDate(new Date() , 'yyyy-MM-dd mm:hh'); 
 * or Util.formateDate(new Date(), 'yyyy/MM/dd mm/hh'); 
 * </code> * @param {Date}date  The date object that needs to be formatted  
 * @param {Object} style  style  
 * @return  Returns the current time after formatting  
 */  
Util.formatDate = function(date, style){ 
      var y = date.getFullYear();  
      var M = "0" + (date.getMonth() + 1);  
      M = M.substring(m.length - 2); 
      var d = "0" + date.getDate(); 
      d = d.substring(d.length - 2);  
      var h = "0" + date.getHours();  
      h = h.substring(h.length - 2);  
      var m = "0" + date.getMinutes();  
      m = m.substring(m.length - 2);  
      return style.replace('yyyy', y).replace('MM', M).replace('dd', d).replace('hh', h).replace('mm', m); 
 }