Return to Snippet

Revision: 31636
at September 9, 2010 23:14 by keanu


Initial Code
public  abstract  class DateUtils {
  private  static  final  Logger logger  = LoggerFactory.getLogger(DateUtils.class ); 
   
  private  static  ThreadLocal<simpledateformat> defaultDateFormat  = new  ThreadLocal<simpledateformat>(); 
   
  public  static  final  SimpleDateFormat getDefaultDateFormat() { 
   if  (null  == defaultDateFormat .get()) { 
    defaultDateFormat .set(new  SimpleDateFormat("yyyy/MM/dd" )); 
   } 
    
    return   defaultDateFormat.get();  
  } 
   
  public  static  final  Date pareseDate(String date) { 
   Date result = null ; 
   try  { 
    result = getDefaultDateFormat().parse(date); 
   } catch  (ParseException e) { 
     logger .error( "Can't parse {} to Date", date);  
   } 
    
   return  result; 
  } 
   
  public  static  final  String formatDate(Date date) { 
   return  getDefaultDateFormat().format(date); 
  } 
}

Initial URL
http://mactruecolor.blogspot.com/2010/09/improve-simpledateformat-performance.html

Initial Description
因為SimpleDateFormat是ThreadSafe且耗資源。

Initial Title
將SimpleDateFormat包裝過的DateUtil

Initial Tags

                                

Initial Language
Java