Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Sun Mar 01 10:03:25 CST 1970 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 java.lang.NumberFormatException: For input string: "33E" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Long.parseLong(Long.java:419) Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019 at java.lang.Long.parseLong(Long.java:468)Thu Jan 01 00:03:25 CST 1970
at java.text.DigitList.getLong(DigitList.java:177) at java.text.DecimalFormat.parse(DecimalFormat.java:1297) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934) Fri Mar 22 10:03:25 CST 2019 at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) Fri Mar 22 10:03:25 CST 2019 at java.text.DateFormat.parse(DateFormat.java:335) at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) Fri Mar 22 10:03:25 CST 2019 at com.resoft.original.framework.common.Test$1.run(Test.java:35) Fri Mar 22 10:03:25 CST 2019 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) Fri Mar 22 10:03:25 CST 2019 at java.lang.Thread.run(Thread.java:662)
null java.lang.NumberFormatException: For input string: ""Tue Jan 01 00:03:25 CST 2019
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)Thu Jan 22 10:03:25 CST 1970
at java.lang.Long.parseLong(Long.java:431) Wed Dec 31 00:00:00 CST 1969 at java.lang.Long.parseLong(Long.java:468) at java.text.DigitList.getLong(DigitList.java:177) Tue Jan 01 00:03:25 CST 2019 at java.text.DecimalFormat.parse(DecimalFormat.java:1297) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1589) Tue Jan 01 00:03:25 CST 2019 at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) at java.text.DateFormat.parse(DateFormat.java:335)Thu Jan 22 00:00:25 CST 1970
at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) Tue Jan 01 00:00:25 CST 2019 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
Thu Jan 01 00:44:40 CST 1970 at java.lang.Thread.run(Thread.java:662) Tue Jan 01 03:03:25 CST 2019 nulljava.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Long.parseLong(Long.java:431) Thu Jan 01 00:00:25 CST 1970 at java.lang.Long.parseLong(Long.java:468) at java.text.DigitList.getLong(DigitList.java:177) at java.text.DecimalFormat.parse(DecimalFormat.java:1297) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1589) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) at java.text.DateFormat.parse(DateFormat.java:335) Fri Mar 22 10:03:25 CST 2019 at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) java.lang.NumberFormatException: multiple pointsnull
Fri Mar 22 10:03:25 CST 2019 at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1082) at java.lang.Double.parseDouble(Double.java:510) Fri Mar 22 10:03:25 CST 2019 at java.text.DigitList.getDouble(DigitList.java:151) at java.text.DecimalFormat.parse(DecimalFormat.java:1302) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) Thu Jul 10 10:03:25 CST 5881580 at java.text.DateFormat.parse(DateFormat.java:335) at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) Fri Mar 22 10:03:25 CST 2019 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) null java.lang.NumberFormatException: multiple points Fri Mar 22 10:03:25 CST 2019 at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1082)
at java.lang.Double.parseDouble(Double.java:510) at java.text.DigitList.getDouble(DigitList.java:151)Fri Mar 22 10:03:25 CST 2019
at java.text.DecimalFormat.parse(DecimalFormat.java:1302) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) at java.text.DateFormat.parse(DateFormat.java:335) Fri Mar 22 10:03:25 CST 2019 at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
......
java.lang.NumberFormatException: For input string: "1.01" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Long.parseLong(Long.java:419) at java.lang.Long.parseLong(Long.java:468) at java.text.DigitList.getLong(DigitList.java:177) Fri Mar 22 10:03:25 CST 2019 at java.text.DecimalFormat.parse(DecimalFormat.java:1297) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) at java.text.DateFormat.parse(DateFormat.java:335) at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) Fri Mar 22 10:03:25 CST 2019 at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) null java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Long.parseLong(Long.java:431) Fri Mar 22 10:03:25 CST 2019 at java.lang.Long.parseLong(Long.java:468) at java.text.DigitList.getLong(DigitList.java:177) at java.text.DecimalFormat.parse(DecimalFormat.java:1297) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) at java.text.DateFormat.parse(DateFormat.java:335) Fri Mar 22 10:03:25 CST 2019 at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) null java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Long.parseLong(Long.java:431) at java.lang.Long.parseLong(Long.java:468) at java.text.DigitList.getLong(DigitList.java:177) at java.text.DecimalFormat.parse(DecimalFormat.java:1297) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1589) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311) at java.text.DateFormat.parse(DateFormat.java:335) at com.resoft.original.framework.common.OriginalDateUtils.parseDate(OriginalDateUtils.java:275) at com.resoft.original.framework.common.Test$1.run(Test.java:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) null Fri Mar 22 10:03:25 CST 2019 Fri Mar 22 10:03:25 CST 2019
分析错误日志有如下错误
会出现日期不对的情况
java.lang.NumberFormatException: For input string xxx
java.lang.NumberFormatException: multiple points
错误原因分析
首先看代码是如何写的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
privatestatic Map<DateFormat, SimpleDateFormat> dateFormaters = new HashMap<DateFormat, SimpleDateFormat>(3, 0.2f);
public Date parse(String text, ParsePosition pos) {
checkNegativeNumberExpression();
int start = pos.index; int oldStart = start; int textLength = text.length();
calendar.clear(); // Clears all the time fields
boolean[] ambiguousYear = { false };
for (int i = 0; i < compiledPattern.length;) { int tag = compiledPattern[i] >>> 8; int count = compiledPattern[i++] & 0xff; if (count == 255) { count = compiledPattern[i++] << 16; count |= compiledPattern[i++]; }
* <h4><a name="synchronization">Synchronization</a></h4> * * <p> * Date formats are not synchronized. * 日期格式不同步。 * It is recommended to create separate format instances for each thread. * 建议为每个线程创建单独的格式实例。 * If multiple threads access a format concurrently, it must be synchronized * externally. * 如果多个线程同时访问一种格式,则必须在外部同步该格式。 * * @see <a href="http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html">Java Tutorial</a> * @see java.util.Calendar * @see java.util.TimeZone * @see DateFormat * @see DateFormatSymbols * @version %I%, %G% * @author Mark Davis, Chen-Lieh Huang, Alan Liu */ public class SimpleDateFormat extends DateFormat {
解决办法
只要在用的时候创建新实例,不用static修饰。
1 2 3 4
public static Date parse(String strDate) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.parse(strDate); }