在JSR-310中计算修改过的朱利安日 [英] Calculate Modified Julian Day in JSR-310
问题描述
如何从JSR-310类计算修改的Julian日,例如 LocalDate
? (在JDK 8中)
How can I calculate the Modified Julian day from a JSR-310 class such as LocalDate
? (in JDK 8)
具体来说,这是连续计数天数,称为修改后的朱利安日,而不是 Julian中的日期日历系统。
Specifically, this is the calculation of the continuous count of days known as "Modified Julian day", not the date in the Julian calendar system.
例如:
LocalDate date = LocalDate.now();
long modifiedJulianDay = ???
推荐答案
简答:
LocalDate date = LocalDate.now();
long modifiedJulianDay = date.getLong(JulianFields.MODIFIED_JULIAN_DAY);
说明:
维基百科文章给出了朱利安日作为概念的最佳描述。简而言之,它是一个简单的,连续的,从某个时代起的天数,其中所选择的时代赋予变体名称。因此,修改后的朱利安日计数从1858-11-17。
The Wikipedia article gives the best description of Julian day as a concept. Put simply, it is a simple, continuous, count of days from some epoch, where the chosen epoch gives the variation its name. Thus, Modified Julian Day counts from 1858-11-17.
JSR-310日期和时间对象实现 TemporalAccessor
接口定义方法 get(TemporalField)
和 getLong(TemporalField)
。这些允许查询特定字段时间的日期/时间对象。提供了四个字段实现,提供Julian日变化:
JSR-310 date and time objects implement the TemporalAccessor
interface which defines the methods get(TemporalField)
and getLong(TemporalField)
. These allow the date/time object to be queried for a specific field of time. Four field implementations are provided offering Julian day variations:
-
JulianFields.MODIFIED_JULIAN_DAY
- 标准修改的朱利安日 -
JulianFields.JULIAN_DAY
- 基于午夜的标准朱利安日概念变体 -
JulianFields.RATA_DIE
- 基于格里高利时代的朱利安日变异 -
ChronoField.EPOCH_DAY
- 基于标准Java / UNIX 1970-01-01的Julian日变体
JulianFields.MODIFIED_JULIAN_DAY
- the standard Modified Julian DayJulianFields.JULIAN_DAY
- a midnight-based variation of the standard Julian day conceptJulianFields.RATA_DIE
- a Julian day variation based on the Gregorian common eraChronoField.EPOCH_DAY
- a Julian day variation based on the standard Java/UNIX 1970-01-01
这些字段只能与 getLong(TemporalField)
一起使用,因为它们返回的数字对于 INT
。如果你调用 now.get(JulianFields.MODIFIED_JULIAN_DAY)
,那么将抛出一个异常:UnsupportedTemporalTypeException:get()方法的无效字段ModifiedJulianDay,使用getLong()而不是
These fields can only be used with getLong(TemporalField)
because they return a number that is too large for an int
. If you call now.get(JulianFields.MODIFIED_JULIAN_DAY)
then an exception will be thrown: "UnsupportedTemporalTypeException: Invalid field ModifiedJulianDay for get() method, use getLong() instead"
请注意,JSR-310只能提供来自 TemporalField
,因此无法表示时间,数字全部基于午夜。计算也使用当地的午夜,而不是UTC,这应该被考虑在内。
Note that JSR-310 can only provide integral numbers from TemporalField
, thus the time-of-day cannot be represented, and the numbers are all based on midnight. The calculations also use local midnight, not UTC, which should be taken into account.
这些字段也可以用于使用<上的方法更新日期/时间对象a href =http://download.java.net/jdk8/docs/api/java/time/temporal/Temporal.html =nofollow> Temporal
:
The fields can also be used to update a date/time object using a method on Temporal
:
result = input.with(JulianFields.MODIFIED_JULIAN_DAY, 56685);
这篇关于在JSR-310中计算修改过的朱利安日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!