建立線程安全的dateformat

注意線程安全,使用DateUtils。亦推薦以下處理: 

private static final ThreadLocal<DateFormat> df = new ThreadLocal<DateFormat>() {
  @Override
   protected DateFormat initialValue() {
    return new SimpleDateFormat("yyyy-MM-dd");
  }
};

說明:安全

若是是JDK8的應用,ide

可使用Instant代替Date,spa

LocalDateTime代替Calendar,線程

DateTimeFormatter代替Simpledateformatter,code

官方給出的解釋:simple beautiful strong immutable thread-safe。orm

相關文章
相關標籤/搜索