A theme
Date formatted string: SimpleDateFormat> DateFormatUtils
Two, code
public void DateFormat(){ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HH-mm"); long startTime1 = System.currentTimeMillis(); for(int i = 0; i< 100000; i++){ DateFormatUtils.format(new Date().getTime(), "yyyyMMdd-HH-mm"); } System.out.println("DateFormatUtils " + (System.currentTimeMillis() - startTime1)); long startTime2 = System.currentTimeMillis(); for(int i = 0; i< 100000; i++){ sdf.format(new Date()); } System.out.println("SimpleDateFormat " + (System.currentTimeMillis() - startTime2)); }
Third, the test results:
DateFormatUtils 238
SimpleDateFormat 120
CONCLUSIONS:
1.SimpleDateFormat little difference between efficiency and DateFormatUtils
There is thread-safety issues 2.SimpleDateFormat, use be used with caution (shared Calendar references)