1. SimpleDateFormat 是線程不安全的,推薦使用如下:
1)聲明SimpleDateFormat變量時 加synchronized修飾。
2)使用DateUtils 工具類
3)使用ThreadLocal,如下:
private static final ThreadLocal<DateFormat> df = new ThreadLocal<DateFormat>() {
protected DateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};
據說《阿里巴巴開發手冊》對於SimpleDateFormat 要求是這樣的: