pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷

Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
本文介紹了1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

鑒于公歷開始日期是 1582 年 10 月 15 日,請考慮以下測試并幫助我了解會發生什么:

Given that Gregorian Calendar start date is 15 Oct 1582, please consider the following tests and please help me understanding what happens:

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import org.junit.Test;

@Test
public void gregorianToDateConversion() {

    GregorianCalendar calendar = null;
    Date date = null;

    calendar = new GregorianCalendar(1582, 9, 04);
    date = calendar.getTime();
    System.out.println("new GregorianCalendar(1582, 9, 4) -> calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
    System.out.println("calendar.getTime() -> Date:" + date);

    calendar = new GregorianCalendar(1582, 9, 05);
    date = calendar.getTime();
    System.out.println("
new GregorianCalendar(1582, 9, 5) -> calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
    System.out.println("calendar.getTime() -> Date:" + date);

    calendar = new GregorianCalendar(1582, 9, 14);
    date = calendar.getTime();
    System.out.println("
new GregorianCalendar(1582, 9, 14) -> calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
    System.out.println("calendar.getTime() -> Date:" + date);

    calendar = new GregorianCalendar(1582, 9, 15);
    date = calendar.getTime();
    System.out.println("
new GregorianCalendar(1582, 9, 15) -> calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
    System.out.println("calendar.getTime() -> Date:" + date);

    String dateToParse = null;

    dateToParse = "1582-10-04";
    System.out.println("
String to parse: " + dateToParse);
    calendar = parseDateTime(dateToParse);
    if(calendar != null) {
        date = calendar.getTime();
        System.out.println("datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
        System.out.println("calendar.getTime() -> Date: " + date);
    }

    dateToParse = "1582-10-05";
    System.out.println("
String to parse: " + dateToParse);
    calendar = parseDateTime(dateToParse);
    if(calendar != null) {
        date = calendar.getTime();
        System.out.println("datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
        System.out.println("calendar.getTime() -> Date: " + date);
    }

    dateToParse = "1582-10-14";
    System.out.println("
String to parse: " + dateToParse);
    calendar = parseDateTime(dateToParse);
    if(calendar != null) {
        date = calendar.getTime();
        System.out.println("datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
        System.out.println("calendar.getTime() -> Date: " + date);
    }

    dateToParse = "1582-10-15";
    System.out.println("
String to parse: " + dateToParse);
    calendar = parseDateTime(dateToParse);
    if(calendar != null) {
        date = calendar.getTime();
        System.out.println("datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
        System.out.println("calendar.getTime() -> Date: " + date);
    }
}
private GregorianCalendar parseDateTime(String s) {
    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
        return datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar();
    } catch (Exception e) {
        e.printStackTrace();
    } 
    return null;
}

結果如下:

new GregorianCalendar(1582, 9, 4) -> calendar[DAY_OF_MONTH [4], MONTH [9], YEAR [1582]] **OK**
calendar.getTime() -> Date:Thu Oct 04 00:00:00 CET 1582 **OK**

new GregorianCalendar(1582, 9, 5) -> calendar[DAY_OF_MONTH [15], MONTH [9], YEAR [1582]] **+ 10 days ??**
calendar.getTime() -> Date:Fri Oct 15 00:00:00 CET 1582 **coherent with calendar**

new GregorianCalendar(1582, 9, 14) -> calendar[DAY_OF_MONTH [24], MONTH [9], YEAR [1582]] **+ 10 days ??**
calendar.getTime() -> Date:Sun Oct 24 00:00:00 CET 1582 **coherent with calendar**

new GregorianCalendar(1582, 9, 15) -> calendar[DAY_OF_MONTH [15], MONTH [9], YEAR [1582]] **OK**
calendar.getTime() -> Date:Fri Oct 15 00:00:00 CET 1582 **OK**

String to parse: 1582-10-04
datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH [4], MONTH [9], YEAR [1582]]
calendar.getTime() -> Date: Mon Sep 24 00:00:00 CET 1582 **Not coherent with calendar. Conversion to julian date?**

String to parse: 1582-10-05
datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH [5], MONTH [9], YEAR [1582]]
calendar.getTime() -> Date: Tue Sep 25 00:00:00 CET 1582 **Not coherent with calendar. Conversion to julian date?**

String to parse: 1582-10-14
datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH [14], MONTH [9], YEAR [1582]] **OK**
calendar.getTime() -> Date: Thu Oct 04 00:00:00 CET 1582 **Not coherent with calendar. Conversion to julian date?**

String to parse: 1582-10-15
datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar() -> 
    calendar[DAY_OF_MONTH [15], MONTH [9], YEAR [1582]] **OK**
calendar.getTime() -> Date: Fri Oct 15 00:00:00 CET 1582 **OK**

你能解釋一下發生了什么嗎?非常感謝.

Could you clarify me what is happening? Thank you very much.

謝謝,我已經修正了我在解析日期格式方面的錯誤:現在都具有 yyyy-MM-gg 的形式,并且不再拋出異常.

Thank you, I've fixed my mistakes about the format of the date to parse: now all have the form yyyy-MM-gg and no exceptions are thrown anymore.

現在我試著澄清我的疑問.

Now I try to clarify my dubts.

是什么決定了我們是否使用公歷?
通過總結:
java.util.GregorianCalendar 表示 1582 年 10 月 15 日之前日期的儒略歷和該日期之后的公歷.對嗎?
因此,這證明了新 GregorianCalendar(...) 中的行為...
如果我這樣做:

What determines whether or not we are using the proleptic gregorian calendar?
By summarizing:
java.util.GregorianCalendar represents a julian calendar for dates before 15 Oct 1582 and a gregorian calendar after this date. Is it right?
So, this justifies the behaviour in the new GregorianCalendar(...)...
If I do:

new GregorianCalendar(1582, 9, 4) 

我有

calendar[DAY_OF_MONTH [4], MONTH [9], YEAR [1582]]  

因為 1582 年 10 月 4 日存在于儒略歷中,而我創建的日歷代表儒略日期.
將此日歷轉換為日期,我們有:

because 4 Oct 1582 exists in the julian calendar and the calendar I've created represents a julian date.
Converting this calendar to date, we have:

Date:Thu Oct 04 00:00:00 CET 1582, consistent with Calendar.  

如果我這樣做:

new GregorianCalendar(1582, 9, 5)   

我得到

calendar[DAY_OF_MONTH [15], MONTH [9], YEAR [1582]]  

因為 10 月 5 日在儒略歷和公歷中都不存在.因此 GregorianCalendar 構造函數在 10 月 4 日之后的 1 天創建了一個日期,即公歷的第一天,即 10 月 15 日.然后用公歷系統表示新日期.
創建一個從 (1582, 9, 5) 到 (1582, 9, 14) 的新日歷傳遞日期時,我也會有同樣的行為.
在上面的例子中,轉換后的 java.util.Date 再次與 Calendar 一致

because the day 5 of October neither exists in julian nor in gregorian calendar. So the GregorianCalendar constructor creates a date exactely 1 day after the 4 of October, that is the first day of the gregorian calendar, the 15 of October. The new date is then expressed in gregorian calendar system.
I'll have the same behaviour creating a new calendar passing dates from (1582, 9, 5) to (1582, 9, 14).
In the example above, the converted java.util.Date is again consistent with the Calendar

Date:Fri Oct 15 00:00:00 CET 1582  

如果我這樣做:

new GregorianCalendar(1582, 9, 15)  

我有

calendar[DAY_OF_MONTH [15], MONTH [9], YEAR [1582]]  

因為 10 月 15 日存在于公歷中,并且新日期在此系統中表示.轉換為 Date 的 Calendar 再次保持一致:

because 15 of October exists in gregorian calendar and the new date is expressed in this system. The Calendar converted into Date is again consistent:

Date:Fri Oct 15 00:00:00 CET 1582  

這意味著 GregorianCalendar 構造函數假定我在日歷系統中輸入了在給定紀元中有效的日期:換句話說,假定如果我輸入的日期早于或等于 10 月 4 日,我認為日期是根據到儒略歷并且日期在這個系統中表示,如果我輸入一個介于 10 月 5 日到 14 日之間的日期,它會計算儒略歷的結束日期(10 月 4 日)和我輸入的日期之間的天數,并將這些天數相加為公歷的開始日期(10 月 15 日)并以公歷表示新日期,如果我輸入的日期在 10 月 15 日之后或等于 10 月 15 日,則假定我輸入的日期是公歷,新日期表示為這個系統.
這一切都正確嗎?
這不是一種預兆行為,對吧?如果日歷是公歷,我希望用

This means that the GregorianCalendar constructor assumes that I enter dates in the calendar system that is valid in the given epoch: in other words assumes that if I enter a date prior then or equal to 04 October I'm thinking the date according to the julian calendar and the date is expressed in this system, if I enter a date between 05 and 14 October it counts the number of days between the end date of julian calendar (04 october) and the date I entered and sums this days to the start date of gregorian calendar (15 October) and express the new date in gregorian system, and if I enter a date after or equal to 15 October it assumes that the date I entered is meant in gregorian calendar and the new date is expressed in this system.
Is all this correct?
This is not a proleptic behaviour, right? If the calendar was a proleptic gregorian calendar I would expect that initializing it with

new GregorianCalendar(1582, 9, 5)  

我會得到

calendar[DAY_OF_MONTH [5], MONTH [9], YEAR [1582]]  

如果日期在公歷系統中不存在,也設置為 10 月 5 日,并且在公歷的第一天之前 10 天,如果我是,它將等于儒略日期 9 月 25 日沒記錯.
我如何決定是否使用公歷?

that is the 5 of October is set also if the date does not exists in the gregorian system and, being 10 days befor the first day of gregorian calendar, it would be equal to the julian date 25 september, if I'm not mistaken.
How can I decide to use the proleptic gregorian calendar or not?

解析一個字符串并通過 XmlGregorianCalendar 創建一個新的 GregorianCalendar,在我看來,這種行為有所不同.
解析1582-10-04"我得到

Parsing a String and creating a new GregorianCalendar passing through the XmlGregorianCalendar, the behaviour seems to me different.
Parsing "1582-10-04" I obtain

calendar[DAY_OF_MONTH [4], MONTH [9], YEAR [1582]] 

(和上面的例子一樣)但是一個日期

(same as the example above..) but a date

Date: Mon Sep 24 00:00:00 CET 1582 

(這里我們有一個儒略日期,對嗎?但在上面的例子中(GregorianCalendar 是由它的構造函數創建的)Date 等于 Calendar.為什么現在它不同了?

(Here we have a julian date, is it right? But in the example above (where the GregorianCalendar was created by its constructor) the Date was equal to the Calendar. Why now it is different?

解析我們得到的字符串1582-10-05"

Parsing the string "1582-10-05" we have

calendar[DAY_OF_MONTH [5], MONTH [9], YEAR [1582]] 

(現在我們有了 Proleptic 公歷,對嗎?)
但又是一個不同的日期

(Now we have a Proleptic gregorian calendar, right?)
But again a different Date

Date: Tue Sep 25 00:00:00 CET 1582 (Julian Date? Why?)  

解析1582-10-14"的行為相同

Same behaviour parsing "1582-10-14"

calendar[DAY_OF_MONTH [14], MONTH [9], YEAR [1582]]  
Date: Thu Oct 04 00:00:00 CET 1582  

如果我們最終解析1582-10-15",我們回來的公歷時代廣告都變得一致:

If we finally parse "1582-10-15", we come back in the Gregorian age ad all become consistent:

calendar[DAY_OF_MONTH [15], MONTH [9], YEAR [1582]]  
Date: Fri Oct 15 00:00:00 CET 1582  

你能幫我理解所有這些行為嗎?
非常感謝你.

Can you help me to understand all this behaviours?
Thank you very much.

編輯 2:

感謝您的回答,如果我仍有疑問.我嘗試了以下代碼:

Thank you for your answers, also if some doubt remains for me. I tried the following code:

GregorianCalendar proleptic = new GregorianCalendar();
proleptic.setGregorianChange(new Date(Long.MIN_VALUE));
proleptic.set(Calendar.DAY_OF_MONTH, 5);
proleptic.set(Calendar.MONTH, 9);
proleptic.set(Calendar.YEAR, 1582);
System.out.println("proleptic [DAY_OF_MONTH ["+proleptic.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+proleptic.get(Calendar.MONTH)+"], YEAR ["+proleptic.get(Calendar.YEAR)+"]");
Date prolepticDate = proleptic.getTime();
System.out.println("prolepticDate ["+prolepticDate+"]");

輸出是:

proleptic [DAY_OF_MONTH [5], MONTH [9], YEAR [1582]
prolepticDate [Tue Sep 25 00:24:07 CET 1582]

現在我的日歷 DAY_OF_MONTH 與我設置的一致,所以我認為這是一種預兆行為,對吧?但是我再次問為什么 getTime() 方法獲得的日期不代表同一天,而是 10 天前.再次感謝.

Now I have the calendar with DAY_OF_MONTH consistent with what I've set, so I think this is a proleptic behaviour, right? But again I ask why the Date, obtained by the getTime() method, does not represent the same day, but 10 days before. Thanks again.

編輯 3:

這個問題對我來說更清楚一些,但并不完全.我沒有詳細理解從 GregorianCalendar 到 Date 的轉換是通過什么邏輯完成的,以及為什么一個預測的公歷和一個傳統的公歷,每個都使用與 DAY、MONTH 和 YEAR 相同的參數構造,并不總是代表相同的時刻.我做了一些進一步的測試.

The question is for me a bit clearer, but not completely. I did not understand in detail by what logic the conversion from GregorianCalendar to Date is done and why a proleptic Gregorian Calendar and a traditional one, each constructed with the same parameters as DAY, MONTH and YEAR, not always represent the same instant of time. I did some further tests.

GregorianCalendar proleptic = null;
GregorianCalendar calendar = null;
Date date = null;

// ---- JULIAN PERIOD ----
proleptic = new GregorianCalendar();
proleptic.clear(); 
proleptic.setGregorianChange(new Date(Long.MIN_VALUE));
proleptic.set(Calendar.DAY_OF_MONTH, 5);
proleptic.set(Calendar.MONTH, Calendar.FEBRUARY);
proleptic.set(Calendar.YEAR, 1582);
System.out.println("proleptic_calendar_5Feb1582 [DAY_OF_MONTH ["+proleptic.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+proleptic.get(Calendar.MONTH)+"], YEAR ["+proleptic.get(Calendar.YEAR)+"]");
date = proleptic.getTime();
System.out.println("date_5Feb1582 from proleptic ["+date+"]");

calendar = new GregorianCalendar(1582, 1, 5);
date = calendar.getTime();
System.out.println("new GregorianCalendar(1582, 1, 5)            -> [DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
System.out.println("new GregorianCalendar(1582, 1, 5) .getTime() -> Date:" + date);

System.out.println("proleptic_calendar_5Feb1582 in millis ["+proleptic.getTimeInMillis()+"], new GregorianCalendar(1582, 1, 5) in millis ["+calendar.getTimeInMillis()+"], millis are equal ["+ (proleptic.getTimeInMillis() == calendar.getTimeInMillis()) +"]");
//--------

System.out.println("
");

// ---- transition period ----
proleptic = new GregorianCalendar();
proleptic.clear(); 
proleptic.setGregorianChange(new Date(Long.MIN_VALUE));
proleptic.set(Calendar.DAY_OF_MONTH, 8);
proleptic.set(Calendar.MONTH, Calendar.OCTOBER);
proleptic.set(Calendar.YEAR, 1582);
System.out.println("proleptic_calendar_8Oct1582 [DAY_OF_MONTH ["+proleptic.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+proleptic.get(Calendar.MONTH)+"], YEAR ["+proleptic.get(Calendar.YEAR)+"]");
date = proleptic.getTime();
System.out.println("date_5Oct1582 from proleptic ["+date+"]");

calendar = new GregorianCalendar(1582, 9, 8);
date = calendar.getTime();
System.out.println("new GregorianCalendar(1582, 9, 8)            -> [DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
System.out.println("new GregorianCalendar(1582, 9, 8) .getTime() -> Date:" + date);

System.out.println("proleptic_calendar_8Oct1582 in millis ["+proleptic.getTimeInMillis()+"], new GregorianCalendar(1582, 9, 8) in millis ["+calendar.getTimeInMillis()+"], millis are equal ["+ (proleptic.getTimeInMillis() == calendar.getTimeInMillis()) +"]");
//--------

System.out.println("
");

// ---- GREGORIAN PERIOD ----
proleptic = new GregorianCalendar();
proleptic.clear(); 
proleptic.setGregorianChange(new Date(Long.MIN_VALUE));
proleptic.set(Calendar.DAY_OF_MONTH, 5);
proleptic.set(Calendar.MONTH, Calendar.DECEMBER);
proleptic.set(Calendar.YEAR, 1582);
System.out.println("proleptic_calendar_5Dec1582 [DAY_OF_MONTH ["+proleptic.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+proleptic.get(Calendar.MONTH)+"], YEAR ["+proleptic.get(Calendar.YEAR)+"]");
date = proleptic.getTime();
System.out.println("date_5Dec1582 from proleptic ["+date+"]");

calendar = new GregorianCalendar(1582, 11, 5);
date = calendar.getTime();
System.out.println("new GregorianCalendar(1582, 11, 5)            -> [DAY_OF_MONTH ["+calendar.get(Calendar.DAY_OF_MONTH)+"], MONTH ["+calendar.get(Calendar.MONTH)+"], YEAR ["+calendar.get(Calendar.YEAR)+"]]");
System.out.println("new GregorianCalendar(1582, 11, 5) .getTime() -> Date:" + date);

System.out.println("proleptic_calendar_5Dec1582 in millis ["+proleptic.getTimeInMillis()+"], new GregorianCalendar(1582, 11, 5) in millis ["+calendar.getTimeInMillis()+"], millis are equal ["+ (proleptic.getTimeInMillis() == calendar.getTimeInMillis()) +"]");
//--------

輸出是:

proleptic_calendar_5Feb1582 [DAY_OF_MONTH [5], MONTH [1], YEAR [1582]
date_5Feb1582 from proleptic [Fri Jan 26 00:00:00 CET 1582]
new GregorianCalendar(1582, 1, 5)            -> [DAY_OF_MONTH [5], MONTH [1], YEAR [1582]]
new GregorianCalendar(1582, 1, 5) .getTime() -> Date:Mon Feb 05 00:00:00 CET 1582
proleptic_calendar_5Feb1582 in millis [-12241069200000], new GregorianCalendar(1582, 1, 5) in millis [-12240205200000], millis are equal [false]

proleptic_calendar_8Oct1582 [DAY_OF_MONTH [8], MONTH [9], YEAR [1582]
date_5Oct1582 from proleptic [Fri Sep 28 00:00:00 CET 1582]
new GregorianCalendar(1582, 9, 8)            -> [DAY_OF_MONTH [18], MONTH [9], YEAR [1582]]
new GregorianCalendar(1582, 9, 8) .getTime() -> Date:Mon Oct 18 00:00:00 CET 1582
proleptic_calendar_8Oct1582 in millis [-12219901200000], new GregorianCalendar(1582, 9, 8) in millis [-12219037200000], millis are equal [false]

proleptic_calendar_5Dec1582 [DAY_OF_MONTH [5], MONTH [11], YEAR [1582]
date_5Dec1582 from proleptic [Sun Dec 05 00:00:00 CET 1582]
new GregorianCalendar(1582, 11, 5)            -> [DAY_OF_MONTH [5], MONTH [11], YEAR [1582]]
new GregorianCalendar(1582, 11, 5) .getTime() -> Date:Sun Dec 05 00:00:00 CET 1582
proleptic_calendar_5Dec1582 in millis [-12214890000000], new GregorianCalendar(1582, 11, 5) in millis [-12214890000000], millis are equal [true]

第一個測試(1582 年 2 月 5 日)指的是屬于儒略歷的時期,第二個(1582 年 10 月 8 日)屬于過渡時期,第三個(1582 年 12 月 5 日)屬于公歷時期.然后我覺得要注意以下幾點:

The first test (5 Feb 1582) refers to a period belonging to the Julian calendar, the second (8 Oct 1582) belongs to the period of transition, the third (5 Dec 1582) to the Gregorian Calendar period. Then I think to notice the following things:

儒略時期

  • 預測的公歷似乎代表了期望的日期
  • 如@Meno Hochschild 所述,獲得的日期被轉換為儒略日期(-10 天)
  • 傳統的公歷似乎也代表了希望的日期...
  • 但是獲取到的Date和之前的不一樣
  • 其實,兩個公歷代表兩個不同的時間瞬間,看毫秒值

過渡期

  • 預測的公歷似乎代表了期望的日期
  • 再次將獲得的日期轉換為儒略日期(-10 天)
  • 傳統的公歷似乎是公歷轉換的結果(10 月 8 日),最初以預測儒略歷表示(10 月 8 日 = 4 天,然后儒略歷 MAX DATE(10 月 4 日)= 3比公歷多天 MIN DATE = 15 + 3 = 10 月 18 日(這是一個假設)
  • 這次獲取的Date好像代表了上面傳統公歷的同一個日期(這次沒有轉換為儒略日?)
  • 兩個公歷再次代表兩個不同的時刻,查看毫秒值

公歷

  • 預測的公歷代表期望的日期
  • 獲取的Date代表相同的日期
  • 傳統的公歷代表所需的日期
  • 獲取的Date代表相同的日期
  • 兩個公歷代表同一時刻,同一毫秒數

你能幫我一一解釋所有這些結果嗎?

Could you help me to explain one by one all of these results?

謝謝.

推薦答案

方法 newXMLGregorianCalendar(s) 必須輸入格式為yyyy-MM-dd"的字符串,即使用 兩位數表示月份中的某天.但是您已經定義了字符串1582-10-4"和1582-10-5"(而不是1582-10-04"和1582-10-05").

Method newXMLGregorianCalendar(s) must be feeded with a string in format "yyyy-MM-dd", that is using TWO digits for the day of month. But you have defined the strings "1582-10-4" and "1582-10-5" (instead of "1582-10-04" and "1582-10-05").

我已經測試了替代品,它可以工作.

I have tested the replacement, and it works.

請記住,XMLGregorianCalendar 非常嚴格,并且還根據 ISO-8601 中的標準約定使用預測公歷.這意味著,它甚至在 1582 年之前就使用公歷閏年規則.這解釋了您的陳述與日歷不一致.轉換為儒略日期?".例如:

Remember that XMLGregorianCalendar is very strict and also uses the proleptic gregorian calendar according to the standard convention in ISO-8601. That means, it uses the gregorian leap year rules even before 1582. This explains your statement "Not coherent with calendar. Conversion to julian date?". For example:

教皇在日期 1582-10-04(舊儒略歷)之后的 10 天撤職,因此在此之后,日期 1582-10-15 在新公歷中緊隨其后.在公歷中,日期 1582-10-14 定義明確,對應于 1582-10-15 的前一天,因此(歷史儒略)日期為 1582-10-04.

The pope had removed 10 days following the date 1582-10-04 (in old julian calendar), so after this the date 1582-10-15 immediately followed in new gregorian calendar. In the proleptic gregorian calendar the date 1582-10-14 is well defined and corresponds to one day before 1582-10-15, hence the (historic julian) date 1582-10-04.

OP 編輯??后更新:

您的問題是什么決定了我們是否使用公歷?"的簡單答案是:你決定.

The simple answer to your question "What determines whether or not we are using the proleptic gregorian calendar?" is: You decide.

詳細說明:如果您使用 XMLGregorianCalendar,那么您使用的是公歷.

In detail: If you use XMLGregorianCalendar then you use the proleptic gregorian calendar.

如果你使用 java.util.GregorianCalendar 那么你默認選擇了日期 1582-10-15 作為公歷的第一天.所有過去的日子都被認為是在儒略歷中.但是,您可以覆蓋默認切換日期.為此,您只需調用方法 setGregorianChange(Date) 帶有適當的參數.new Date(Long.MIN_VALUE) 的參數設置預測公歷,而 new Date(Long.MAX_VALUE) 的參數設置預測儒略歷.

If you use java.util.GregorianCalendar then you have choosen the date 1582-10-15 as the first day of gregorian calendar by default. All former days are considered as being in julian calendar. You can override the default switch date however. For this to make work you just call the method setGregorianChange(Date) with an appropriate argument. An argument of new Date(Long.MIN_VALUE) sets the proleptic gregorian calendar while an argument of new Date(Long.MAX_VALUE) sets the proleptic julian calendar.

同樣重要的是要注意

a) 大多數國家在 1582 年 10 月 15 日沒有改用公歷(只有主要的天主教國家),

a) most countries did not switch to gregorian calendar in 1582-10-15 (only major catholic countries),

b) 歷史日期由其他因素進一步確定,例如不同的年初(這使得 JDK 中的整個 julian-gregorian-calendar-implementation 完全不足 - 目前沒有提供支持的庫).

b) historical dates are further determined by other factors like different start of year (which makes the whole julian-gregorian-calendar-implementation in JDK completely insufficient - currently there is no library which gives support).

EDIT-2 后更新:

輸出 proleptic [DAY_OF_MONTH [5], MONTH [9], YEAR [1582] 符合預期,并保留了 proleptic 公歷中定義的輸入(1582-10-15 前 10 天)向后應用公歷閏年規則).

The output proleptic [DAY_OF_MONTH [5], MONTH [9], YEAR [1582] is as expected and conserves the input as defined in proleptic gregorian calendar (10 days before 1582-10-15 applying the gregorian leap year rules backwards).

輸出 prolepticDate [Tue Sep 25 00:24:07 CET 1582] 是一個完全不同的故事.但是如果您記得您確實在 java.util.Date 上調用了方法 toString(),那就可以理解了.此方法在內部實例化一個新的公歷對象,默認開關為 1582-10-15. Date-對象不知道(也沒有內部狀態)設置公歷更改的日期,因此它的 toString() 方法只應用默認值.最后,預測日歷對象只是重新計算/重新格式化為 Date.toString() 特定格式的儒略歷表示.即:1582-09-25(切換前十天).

The output prolepticDate [Tue Sep 25 00:24:07 CET 1582] is a completely different story. But it is understandable if you remember that you really called the method toString() on java.util.Date. This method internally instantiates a new gregorian calendar object with the default switch of 1582-10-15. A Date-object has no idea (and no internal state) about setting the date for gregorian change, so its toString()-method just applies the default. Finally the proleptic calendar object is just recalculated/reformatted to a julian calendar representation in the specific format of Date.toString(). That is: 1582-09-25 (ten days before the switch).

由于@VGR 的評論而更新:

我的測試驗證,例如對于預測日期 1582-10-05,XMLGregorianCalendar 和新 GregorianCalendar 的專門構造自 unix 以來以毫秒為單位產生相同的時間-epoch,見這里:

My test verifies that for example for the proleptic date 1582-10-05 both XMLGregorianCalendar and a specialized construction of a new GregorianCalendar yield the same time in millis since unix-epoch, see here:

String s = "1582-10-05";
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
GregorianCalendar xml = datatypeFactory.newXMLGregorianCalendar(s).toGregorianCalendar();

GregorianCalendar proleptic = new GregorianCalendar();
proleptic.clear(); // very important for proper comparison to reset time part to zero
proleptic.setGregorianChange(new Date(Long.MIN_VALUE));
proleptic.set(Calendar.DAY_OF_MONTH, 5);
proleptic.set(Calendar.MONTH, Calendar.OCTOBER);
proleptic.set(Calendar.YEAR, 1582);

boolean isEqual = (xml.getTimeInMillis() == proleptic.getTimeInMillis());

System.out.println("XML-millisSinceEpoch: " + xml.getTimeInMillis());
System.out.println("Proleptic-millisSinceEpoch: " + proleptic.getTimeInMillis());
System.out.println("XML==Proleptic (1582-10-05): " + isEqual);
System.out.println(
    "proleptic [DAY_OF_MONTH [" + proleptic.get(Calendar.DAY_OF_MONTH) + "], MONTH ["
    + proleptic.get(Calendar.MONTH) + "], YEAR [" + proleptic.get(Calendar.YEAR) + "]"
);
System.out.println("Date.toString() [" + proleptic.getTime() + "]");

輸出:

XML-millisSinceEpoch: -12220160400000
Proleptic-millisSinceEpoch: -12220160400000
XML==Proleptic (1582-10-05): true
proleptic [DAY_OF_MONTH [5], MONTH [9], YEAR [1582]
Date.toString() [Tue Sep 25 00:00:00 CET 1582]

這篇關于1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
The correct way to set and get hour, minutes, sec(設置和獲取小時、分鐘、秒的正確方法)
主站蜘蛛池模板: 河南道路标志牌_交通路标牌_交通标志牌厂家-郑州路畅交通 | 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 橡胶接头_橡胶软接头_可曲挠橡胶接头-巩义市创伟机械制造有限公司 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 安徽集装箱厂-合肥国彩钢结构板房工程有限公司 | 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 衬塑管道_衬四氟管道厂家-淄博恒固化工设备有限公司 | 板框压滤机-隔膜压滤机-厢式压滤机生产厂家-禹州市君工机械设备有限公司 | 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 东莞ERP软件_广州云ERP_中山ERP_台湾工厂erp系统-广东顺景软件科技有限公司 | PE拉伸缠绕膜,拉伸缠绕膜厂家,纳米缠绕膜-山东凯祥包装 | 数字展示在线_数字展示行业门户网站 | 铝板冲孔网,不锈钢冲孔网,圆孔冲孔网板,鳄鱼嘴-鱼眼防滑板,盾构走道板-江拓数控冲孔网厂-河北江拓丝网有限公司 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 全温恒温摇床-水浴气浴恒温摇床-光照恒温培养摇床-常州金坛精达仪器制造有限公司 | 厌氧工作站-通用型厌氧工作站-上海胜秋科学仪器有限公司 | 胃口福饺子加盟官网_新鲜现包饺子云吞加盟 - 【胃口福唯一官网】 | 粉末冶金-粉末冶金齿轮-粉末冶金零件厂家-东莞市正朗精密金属零件有限公司 | 棉柔巾代加工_洗脸巾oem_一次性毛巾_浴巾生产厂家-杭州禾壹卫品科技有限公司 | 中国品牌门窗网_中国十大门窗品牌_著名门窗品牌 | 无负压供水设备,消防稳压供水设备-淄博创辉供水设备有限公司 | 瑞典Blueair空气净化器租赁服务中心-专注新装修办公室除醛去异味服务! | 吸音板,隔音板,吸音材料,吸音板价格,声学材料 - 佛山诺声吸音板厂家 | 纯水设备_苏州皙全超纯水设备水处理设备生产厂家 | 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 上海道勤塑化有限公司| 科威信洗净科技,碳氢清洗机,超声波清洗机,真空碳氢清洗机 | uv固化机-丝印uv机-工业烤箱-五金蚀刻机-分拣输送机 - 保定市丰辉机械设备制造有限公司 | 搜活动房网—活动房_集装箱活动房_集成房屋_活动房屋 | 破碎机_上海破碎机_破碎机设备_破碎机厂家-上海山卓重工机械有限公司 | 无线联网门锁|校园联网门锁|学校智能门锁|公租房智能门锁|保障房管理系统-KEENZY中科易安 | 手板-手板模型-手板厂-手板加工-生产厂家,[东莞创域模型] | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 地图标注-手机导航电子地图如何标注-房地产商场地图标记【DiTuBiaoZhu.net】 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 铣刨料沥青破碎机-沥青再生料设备-RAP热再生混合料破碎筛分设备 -江苏锡宝重工 | 济南办公室装修-厂房装修-商铺装修-工装公司-山东鲁工装饰设计 | 颚式破碎机,圆锥破碎机,制砂机-新乡市德诚机电制造有限公司 | uv机-uv灯-uvled光固化机-生产厂家-蓝盾机电 |