在计算和保存数据库期间如何处理时间(例如 14:33)?我可以在 HSQL 数据库中使用什么数据类型?
我想计算工作量或休息时间等内容。是否有内置的可能性将时间转换为小数?
谢谢!
最佳答案
对于时间表示,最方便的类型应该是 Joda Time's LocalTime
.
有多个转换器可用于 map the LocalTime
type to the database .
您需要JAR包joda-time
and joda-time-hibernate
.
您的域类可能如下所示:
import org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime
import org.joda.time.LocalTime
class TimeDomain {
LocalTime localTime
static mapping = {
localTime type: PersistentLocalTimeAsTime
}
// business logic would belong to a service class
LocalTime plusMinutes(int minutes) {
localTime.plusMinutes(minutes)
}
}
关于grails - 在 gorm 中使用时间的数据类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345286/