在我的数据库中,我有一个列类型:datetime。
列数据示例:2009-02-03 19:04:23.0
我正在使用:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
定义我的日期格式。
我使用groovysql读取表,并为每一行添加一个新的samplej对象(映射到一个新表samplej)。
这里是我的结束语:
def sampleQuery(int dataset) {
sqlModule.eachRow("""
select b.*
from dataset a, array_data b
where dataset_id = "${dataset}"
and a.array_data_id = b.array_data_id ;""")
{
def addSample= new SampleJ(it.toRowResult())
addSample.id = "${it.array_data_id}" as int
addSample.dateCreated = dateFormat.parse("${it.date_created}")
//addSample...(more columns)
addSample.save()
}
}
当我检查临时表“samplej”时,我的所有日期都与“$it.date created”不匹配。
所有日期都设置为“new date()”(结束执行时间)。
通过调试器:
“$it.date_created”定义为“2009年2月3日星期二19:04:23 cst”,对应于(2009-02-03 19:04:23.0)。我应该有这个约会!
如何解决此问题?我没有错误,只是日期不对。
有没有一个简单的方法来定义我在samplej的日期?
addsample.date created=dateformat.parse(“$it.date”)的替代方法?