How to grab milliseconds in grails domain
I have a grails domain that stores data in MySQL.
In it I have a property Date
that creates a field DateTime
in the DB. However, I would also like to record the milliseconds in addition to the date.
Is there a way to capture milliseconds?
Example:
Class MyClass {
Date dateCreated
}
stores data in MySQL like 2014-10-06 16:21:57
, but I would also like to record milliseconds.
source to share
MySQL 5.6.4 and up can store milliseconds in the database for datetime objects by specifying the number of decimal points for the object. (Read more here: MySQL Reference Manual ). By default, Grails / Gorm does not. Fortunately, this can be easily solved by defining the sqlType on the domain like this:
class ExampleDomain {
Date date
static mapping = {
date sqlType: 'datetime(3)'
}
}
source to share