日期(dateFormat.parse( “串号”)。的getTime())错误
问题描述:
我有一个字符串日期2020-01-14 00:00:00.0
当我转换使用日期(dateFormat.parse( “串号”)。的getTime())错误
new java.sql.Date(dateFormat.parse("2020-01-14 00:00:00.0").getTime())
此字符串日期,这将导致日期为0019-07-13
我没有得到它是如何转换的串...
请帮我
谢谢
答
DateFormat.parse()
是抽象的,SimpleDateFormat.parse()
是+ - 120行长。据推测,你使用SimpleDateFormat来进行解析。如果您没有将特定格式字符串传递给您对SimpleDateFormat的构造函数的调用,则SimpleDateFormat默认使用当前Locale中指定的格式进行初始化。
确保您初始化dateFormat
如下
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
,你的问题应该消失。
告诉我们'dateFormat'是如何定义的。 – adarshr
'dateFormat'是什么? – Amanpreet
@Amanpreet:在Date(...)构造函数中调用的属性'dateFormat'是指。 – home