Groovy 中两个日期之间的持续时间 [英] Duration between two dates in Groovy

查看:23
本文介绍了Groovy 中两个日期之间的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Groovy 有没有办法获取两个 Date 对象之间的持续时间?我正在寻找的持续时间格式类似于:2 天、10 小时、30 分钟...

Is there a way in Groovy to get the duration between two Date objects? The duration format I'm looking for would be something like: 2 days, 10 hours, 30 minutes...

谢谢

推荐答案

TimeCategory 有一些获取持续时间的方法.你可以像

TimeCategory has some methods for getting a duration. You could use it like

use(groovy.time.TimeCategory) {
    def duration = date1 - date2
    print "Days: ${duration.days}, Hours: ${duration.hours}, etc."
}

这篇关于Groovy 中两个日期之间的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆