I have a grails domain that stores data in MySQL.
In it I have a Date property which creates a DateTime field in the DB. However, I also wish to capture the milliseconds in addition to the date.
Is there a way to capture milliseconds?
Example:
Class MyClass {
Date dateCreated
}
stores data in MySQL as 2014-10-06 16:21:57 but I'd like to capture milliseconds as well.
MySQL 5.6.4 and up can save milliseconds in the database for datetime objects by defining the amount of fractional points for the object. (Read more here: MySQL reference manual). By default Grails/Gorm doesn't do this. Fortunately, this is easily solved by defining a sqlType in the domain like this:
class ExampleDomain {
Date date
static mapping = {
date sqlType: 'datetime(3)'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With