java.lang.NumberFormatException: multiple points已解决

来源:互联网 发布:js删除数组中某个元素 编辑:程序博客网 时间:2024/06/05 14:06

原因是SimpleDateFormat不支持多线程导致的,解决代码如下


// 解决SimpleDateFormat多线程问题private static final ThreadLocal<DateFormat> sdf_yyyy_MM_dd = new ThreadLocal<DateFormat>() {@Overrideprotected DateFormat initialValue() {return new SimpleDateFormat("yyyy-MM-dd");}};private static final ThreadLocal<DateFormat> sdf_yyyy_MM_dd_HH_mm = new ThreadLocal<DateFormat>() {@Overrideprotected DateFormat initialValue() {return new SimpleDateFormat("yyyy-MM-dd HH:mm");}};private static final ThreadLocal<DateFormat> sdf_yyyy_MM_dd_HH_mm_ss = new ThreadLocal<DateFormat>() {@Overrideprotected DateFormat initialValue() {return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");}};public static Date sdf_parse(ThreadLocal<DateFormat> sdf, String str) {Date d = null;if (StringUtils.isNotBlank(str)) {try {d = sdf.get().parse(str);} catch (ParseException e) {e.printStackTrace();}}return d;}public static String sdf_format(ThreadLocal<DateFormat> sdf, Date date) {String str = "";if (date != null) {str = sdf.get().format(date);}return str;}



在别的地方调用

sdf_format(sdf_yyyy_MM_dd_HH_mm_ss, issuedDate)sdf_parse(sdf_yyyy_MM_dd_HH_mm, isDate + " " + issuedTime)


阅读全文
0 0
原创粉丝点击