date - Grails插入并在脚手架上显示错误的日期值

标签 date grails scaffolding

通过以下示例,当脚手架完成时,我做了很多尝试以获取正确的日期。
使用的数据库是MS SQL Server 2008。

细节在下面给出。问题是无论何时插入日期,SQL Server都会保留错误的日期。它也显示错误的日期。
例如:-当我选择日期为2/2/2015时,它将值1/31/2015存储在数据库中。它显示CT 2015-01-31 00:00:00。这也正在做脚手架。有人可以帮忙吗?

费用域类

package moneytracker

class Expense {
    Date tranDate
    Float amount

    static belongsTo = [category:Category]

    static constraints = {
        amount Default:0.00
    }

    static mapping={
        id column: "intTranId", sqlType:"Integer",generator: "identity"
        amount column: 'fltAmt'
        tranDate column: 'dtDate',format:'yyyy-MM-DD'
        category column: 'intCatId'
        version false
    }
}

表结构
TABLE [dbo].[expense]
    [intTranId] [int] IDENTITY(1,1) NOT NULL-Primary key
    [fltAmt] [float] NOT NULL,
    [dtDate] [date] NOT NULL,
    [intCatId] [numeric](19, 0) NOT NULL Foreign key to Category table

我尝试了不同的格式,也没有格式。域中没有任何格式,它会插入正确的值,但是在显示时会显示错误的值,例如几天前...

有人可以帮我吗?

最佳答案

出现此问题的原因是SQL Server数据库的jdbc驱动程序不兼容。我也遇到了这个问题,并从this related question找到了解决方案

关于date - Grails插入并在脚手架上显示错误的日期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28522485/

相关文章:

mysql - 如何将字符串中的月份名称转换为短月份

json - 向 Grails 发送日期时的 GORM 默认日期格式

grails - 阻止 Grails 在 Controller 中生成某些方法?

grails - 如何创建显示JSON View 的grails 3插件?

mysql - 序列不包含匹配元素脚手架 Visual Studio 2015

ruby-on-rails - Rails- Controller :notice - Add a variable?

javascript - 从对象数组中获取本月的第一天

python - 如何使用 SQLAlchemy 从数据库中获取当前日期和时间

java - SimpleDateFormat 宽容导致意外行为

ruby-on-rails - RoR - 脚手架 - 未定义的方法 'to_sym' for nil :NilClass only an error in the edit method