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:
我需要读一个给我的sqlite数据库,所以我不能在表格中更改日期格式(yyyy-MM-dd)。当我尝试使用ormlite为我生成对象时,使用以下注释:
@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?
有什么地方我可以告诉ormlite我想用“yyyy-MM-dd”作为日期字符串?
1 个解决方案
#1
15
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.
如果您查看有关日期格式的ORMLite文档,您会看到它提到了@ DatabaseField.format字段。以下是格式的javadoc。这允许您设置日期格式。
The following should work:
以下应该有效:
@DatabaseField(columnName = "REVISION_DATE", dataType = DataType.DATE_STRING,
format = "yyyy-MM-dd")
public Date revisionDate;
#1
15
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.
如果您查看有关日期格式的ORMLite文档,您会看到它提到了@ DatabaseField.format字段。以下是格式的javadoc。这允许您设置日期格式。
The following should work:
以下应该有效:
@DatabaseField(columnName = "REVISION_DATE", dataType = DataType.DATE_STRING,
format = "yyyy-MM-dd")
public Date revisionDate;