Grails Gorm 查找从数据库中检索不同的日期值

Grails Gorm find retrieves different date value compared from database

在我的 Oracle 数据库中,有一个 Agreement table,其列 effectivityDate 的数据类型为 DATE。当我尝试查询某一行时

select * from agreement where id = 'GB'

它 return 具有此值的一行:

id: GB
name: MUITF - Double bypass
...
effectivityDate: 7/2/2015

我为此创建了一个 Grails Domain class:

class Agreement implements Serializable {
    String id
    Date effectivityDate

    static mapping = {
        table "agreement"
        varsion: false
        id column: "id"
        name column: "name"
        ...
        effectivityDate column: "effectivityDate"
    }
}

但是当我尝试在 groovy 上查询它时使用:

Agreement a = Agreement.findById("GB")
println a

它return这个对象:

[id:GB, name:MUITF - Double bypass, ..., effectivityDate: 2015-07-01T16:00:00Z]
                                                          ^^^^^^^^^^^^^^^^^^^^

我的问题是,为什么直接从数据库中获取的日期与 gorm 检索到的日期不同?这与时区有关吗?

刚刚在您的个人资料中看到您来自菲律宾(PHT,GMT+8)。

2015-07-01T16:00:00Z === 2015-07-02T00:00:00+08:00开始,最可能的原因是您在查询数据库时使用PHT时区显示日期,而在querying/displaying时使用GMT/Zulu时区显示groovy/grails.