Groovy であるタイムスタンプを別のタイムスタンプから減算し、経過した時間数を取得する必要があります。タイムスタンプは MySQL から取得されます。簡単な計算を行うと、日数がゼロの整数に丸められます。
endDate - startDate は丸められた整数を返します
2.35時間などの結果が欲しい
groovy.time.TimeCategory
次のように使用できます。
// create two timestamps
import java.sql.Timestamp
def dates = ['2012/08/03 09:00', '2012/08/03 10:30']
def (Timestamp a, Timestamp b) = dates.collect {
new Timestamp( Date.parse( 'yyyy/MM/dd hh:mm', it ).time )
}
// Then compare them with TimeCategory
use(groovy.time.TimeCategory) {
def duration = b - a
println "${duration.days}d ${duration.hours}h ${duration.minutes}m"
}
どちらが印刷されますか:
0d 1h 30m