【发布时间】:2013-09-06 13:15:36
【问题描述】:
我需要将传入的日期字符串格式“20130212”(YYYYMMDD) 转换为 12/02/2013 (DD/MM/YYYY)
使用ThreadLocal。我知道没有ThreadLocal 的方法。谁能帮帮我?
没有ThreadLocal的转化:
final SimpleDateFormat format2 = new SimpleDateFormat("MM/dd/yyyy");
final SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd");
final Date date = format1.parse(tradeDate);
final Date formattedDate = format2.parse(format2.format(date));
【问题讨论】:
-
为什么需要使用 ThreadLocal?
-
因为 SimpleDateFormats(以及实际上大多数其他 Format 实例)不是线程安全的。有关此主题,请参阅我的 blog post。
标签: java simpledateformat date-conversion