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 要求是这样的: