且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JSR-310中计算修改过的朱利安日

更新时间:2023-01-17 08:08:50

简答:

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 - the standard Modified Julian Day
  • JulianFields.JULIAN_DAY - a midnight-based variation of the standard Julian day concept
  • JulianFields.RATA_DIE - a Julian day variation based on the Gregorian common era
  • ChronoField.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.

这些字段也可以用于使用 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);