java.text.ParseException:无法解析的日期:yyyy-MM-dd HH:mm:ss.SSSSSS [英] java.text.ParseException: Unparseable date: yyyy-MM-dd HH:mm:ss.SSSSSS

查看:229
本文介绍了java.text.ParseException:无法解析的日期:yyyy-MM-dd HH:mm:ss.SSSSSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到 ParseException 以获取以下代码

    String dateStr = "2011-12-22 10:56:24.389362";
    String formatStr = "yyyy-MM-dd HH:mm:ss.SSSSSS";
    Date testDate = null;
    SimpleDateFormat sdf= new SimpleDateFormat(formatStr);
    sdf.setLenient(false);
    testDate = sdf.parse(dateStr);

    System.out.println("CHECK DATE " + sdf.format(testDate));

线程main中的异常java.text.ParseException:无法解析的日期: 2011-12-22 10:56:24.389362
at java.text.DateFormat.parse(DateFormat.java:337)

如果我注释掉 sdf.setLenient(false)这一行,那么我会在输出中看到时间差
CHECK DATE 2011-12-22 11:02:53.000362

If I comment out the line sdf.setLenient(false), then I see a time difference in the ouput CHECK DATE 2011-12-22 11:02:53.000362

我做错了什么?

推荐答案

'S'是毫秒。一秒钟内有1000(0到999)毫秒。 389362大于999.额外的389000毫秒转换为389秒,或6分29秒并添加到时间。

'S' is for millisecond. There are 1000 (0 to 999) milliseconds in a second. 389362 is greater than 999. The extra 389000 milliseconds are getting converted to 389 seconds, or 6 minutes 29 seconds and added to the time.

这篇关于java.text.ParseException:无法解析的日期:yyyy-MM-dd HH:mm:ss.SSSSSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆