ormlite read Date as 'yyyy-MM-dd'

◇◆丶佛笑我妖孽 提交于 2019-12-09 16:16:27

问题


I need to read a sqlite databse given to me, so I cannot change the Date format (yyyy-MM-dd) in the tables. When I try to use ormlite to generate object for me, using the following annotation:

@DatabaseField(columnName = "REVISION_DATE", dataType = DataType.DATE_STRING)
public Date revisionDate;

it gives me the following error:

java.sql.SQLException: Problems with column 3 parsing date-string '2012-05-01'
      using 'yyyy-MM-dd HH:mm:ss.SSSSSS'

is there any place I can tell ormlite I want to use "yyyy-MM-dd" as the date string?


回答1:


If you take a look at the ORMLite documentation about date formats you will see that it mentions the @DatabaseField.format field. Here are the javadocs for format. This allows you to set the Date format.

The following should work:

@DatabaseField(columnName = "REVISION_DATE", dataType = DataType.DATE_STRING,
      format = "yyyy-MM-dd")
public Date revisionDate;


来源:https://stackoverflow.com/questions/12847484/ormlite-read-date-as-yyyy-mm-dd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!