1

我正在尝试将日期从一种格式转换为另一种格式

输入字符串 - 2012-11-07-121603 (yyyy-MM-dd-HH-mm-ss)

输出字符串 - 2012-11-07-12:16:03:000 (yyyy-MM-dd-HH:mm:ss:SSS)

ThreadSafeSimpleDateFormatUtil simpleDateFormat = new ThreadSafeSimpleDateFormatUtil(GenericConstants.DATE_FORMAT.YYYY_MM_DD_HH_MM_SS.toString());
final Date parsedDate = simpleDateFormat.parse(bulkCollectionTime);
simpleDateFormat = new ThreadSafeSimpleDateFormatUtil(GenericConstants.DATE_FORMAT.YYYY_MM_DD_HH_MM_SS_SSS.toString());
writeBean.setTimestamp(simpleDateFormat.format(parsedDate));

但它抛出以下错误:

java.text.ParseException: Unparseable date: "2012-11-07-121603"
    at java.text.DateFormat.parse(DateFormat.java:337)
    at com.belgacom.rosy.rebecca.utils.ThreadSafeSimpleDateFormatUtil.parse(ThreadSafeSimpleDateFormatUtil.java:39)
4

3 回答 3

2

看起来输入格式应该在小时、分钟和秒之间没有“-”:

2012-11-07-121603 (yyyy-MM-dd-HHmmss)
于 2012-12-11T08:48:54.337 回答
1
Input String - 2012-11-07-121603 (yyyy-MM-dd-HH-mm-ss)

它会匹配的错误模式yyyy-MM-dd-HHmmss

于 2012-12-11T08:48:03.513 回答
0
于 2018-03-08T00:49:22.523 回答