Joda-Time:Period,Interval和Duration之间有什么区别? [英] Joda-Time: what's the difference between Period, Interval and Duration?

查看:290
本文介绍了Joda-Time:Period,Interval和Duration之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Joda-Time 2中,三种时间跨度有什么区别:

In Joda-Time 2, what is the difference between the three kinds of time spans:


  1. 为什么我们需要三个班级吗?

  1. Why do we need three classes?

哪一个表现更好?

为什么划分期间或持续时间或间隔实例未实现?例如。 p = p.divideBy(2);

Why is dividing a Period or Duration or Interval instance not implemented? E.g. p = p.divideBy(2);


推荐答案

需要3个类,因为它们代表不同的概念,因此需要选择适当的工作而不是相对性能。来自文档,我在斜体中添加了评论

3 classes are needed because they represent different concepts so it is a matter of picking the appropriate one for the job rather than of relative performance. From the documentation with comments added by me in italics:

Joda-Time中的间隔表示从1毫秒开始的时间间隔瞬间到了另一个瞬间。两个时刻都是日期时间连续统中的完全指定的时刻,并带有时区。 具体时间定义为例如这可能是昨天20:00:00GTT和今天早上09:00:00GTT之间的时间间隔。

An interval in Joda-Time represents an interval of time from one millisecond instant to another instant. Both instants are fully specified instants in the datetime continuum, complete with time zone. Specific times are defined e.g. this might be the interval between 20:00:00GMT yesterday and 09:00:00GMT this morning.

持续时间 Joda-Time表示以毫秒为单位测量的持续时间。持续时间通常从间隔获得。 即。我们可以从间隔的结尾开始减去以获得持续时间

A duration in Joda-Time represents a duration of time measured in milliseconds. The duration is often obtained from an interval. i.e. we can subtract start from end of an interval to derive a duration

Joda-Time中的期间代表一段时间根据领域定义,例如,3年5个月2天和7小时。这与持续时间的不同之处在于它以毫秒为单位是不精确的。通过指定相对于的时间(包括时间顺序和时区),只能将句点解析为精确的毫秒数。 e.g。考虑1年的时间,如果我们将其添加到1月1日,我们将始终在1月1日到达,但持续时间将取决于干预年是否是闰年。同样地,如果我们将1个月添加到一个月的第一个月,那么我们将在下个月的第一个月到达,但持续时间(以毫秒为单位)将根据有问题的月份而变化

A period in Joda-Time represents a period of time defined in terms of fields, for example, 3 years 5 months 2 days and 7 hours. This differs from a duration in that it is inexact in terms of milliseconds. A period can only be resolved to an exact number of milliseconds by specifying the instant (including chronology and time zone) it is relative to. e.g. consider the period of 1 year, if we add this to January 1st we will always arrive at the next January 1st but the duration will depend on whether the intervening year is a leap year or not. Similarly if we add 1 month to the 1st of a month then we will arrive at the 1st of the next month but the duration (in milliseconds) will vary based on the month in question

对于问题3,实际上并不需要划分持续时间的特定方法,因为我们总是可以从持续时间获得毫秒数 long (使用 getMillis()),除以它并构造一个新的持续时间(使用 new Duration(long持续时间))。

For question 3, A specific method to divide a duration is not really needed because we can always get the number of milliseconds from the duration as a long (using getMillis()), divide it and construct a new duration (using new Duration(long duration)).

根据上述期间的定义,划分期间并不具有实际意义。例如什么是半个月? (其长度取决于哪个月)。

Dividing a period doesn't really have a real meaning based on the definition of a period above. e.g. what is half a month? (its length would depend on which month).

这篇关于Joda-Time:Period,Interval和Duration之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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