October 4, 1582 is the day of the week

Source: Internet
Author: User

Let's take a look at the following C #Program:

 01:  Using System; 02:  Using System. Globalization; 03:  04:  Class  Program05: { 06:    Static void Main () 07: {08:      Console . Writeline ( Cultureinfo . Currentculture. calendar ); 09:      For ( VaR Dt = New  Datetime (1582, 10, 4); dt <= New  Datetime (1582, 10, 15); dt = DT. adddays (1 )) 10:        Console . Writeline (Dt. tostring ("Dddd yyyy-mm-dd" )); 11: } 12: }

The running result is as follows:

System. Globalization

In this case, October 4, 1582 is Monday.

Is that true? Let's take a look at the following Java program:

Import Java. util. *; public class gregoriantest {public static void main (string [] ARGs) {for (gregoriancalendar dt = new gregoriancalendar (1582, 9, 4); DT. compareto (New gregoriancalendar (1582, 9, 15) <= 0; DT. add (calendar. day_of_month, 1) system. out. println (DT. gettime ());}}

Compile and run on Ubuntu 10.04:

Ben @ Ben-1520 :~ /Work $Javac gregoriantest. JavaBen @ Ben-1520 :~ /Work $Java gregoriantestThu Oct 04 00:00:00 CST 1582fri Oct 15 00:00:00 CST 1582ben @ Ben-1520 :~ /Work $

Note that in the constructor of the Java. util. gregoriancalendar class, the month starts from 0, so 9 indicates October.

We can see the following two points:

    1. Thursday, January 1, October 4, 1582.
    2. The next day of June October 4, 1582 is: February 1, October 15, 1582, Friday.

Who is correct?

Let's take a look at the description of the Java. util. gregoriancalendar class:

Gregoriancalendar is a specific subclass of calendar. It provides a standard calendar system used by most countries/regions in the world.

Gregoriancalendar is a hybrid calendar that supports both the Confucian and Gregorian calendars with the support of a single break. By default, it corresponds to the Gregorian calendar date when the Gregorian calendar was created (some countries/regions were created in October 15, 1582 and later in other countries/regions ). The caller can change the start date by calling setgregorianchange.

In history, in those countries/regions that first adopted the Gregorian calendar, the year October 4, 1582 (after the Gregorian calendar) is the year October 15, 1582 (the Gregorian calendar ). The calendar correctly simulates these changes. Before the gregoriancalendar begins, gregoriancalendar implements a rule calendar. The only difference between the Gregorian calendar and the Confucianism is the leap year rule. The rru indicates that every four years is a leap year, while the Gregorian calendar ignores the century years that cannot be divisible by 400.

GregoriancalendarExpectedGregallies and ruru. That is to say, the date can be calculated by infinitely backward or forward the current rule in time. Therefore, you can use gregoriancalendar to generate meaningful and consistent results for all years. However, the date obtained by gregoriancalendar is only accurate in history after, A.M. Prior to this date, the application of the leap year rule had no regularity, and there was no even a Confucianism before the 45 BC.

This makes it clear that the Java platform is correct, while the datetime In the. NET Framework base class library is problematic.

Gregorian calendar is the current Gregorian calendar in China.

Run the following command in the Ubuntu 10.04 operating system:

Ben @ Ben-1520 :~ /Work $Ncal-3-s it 10 10 1582September 15 82 October 15 82 November 15 5 5 6 1234 5 6 5 6 6 1234 5 6 1 1 1 2 3 4 15 16 1 2 3 5 6 2 3 4 5 6 5 6 6 7 8 17 18 19 20 21 22 23 7 8 9 10 11 12 9 10 11 12 13 14 15 15 24 25 26 27 28 29 30 14 15 16 18 19 2016 17 18 19 20 21 22 31 21 22 23 24 25 26 2723 24 25 26 27 28 29 29 3030 Ben @ Ben-1520: ~ /Work $

We can see that July 22, October 4, 1582 is indeed a Thursday, and the next day is Friday, July 22, October 15, 1582. Therefore, July 22, October 1582 only has 21 days.

If you have downloaded Visual J # redistributable packages, you can also use the java. util. gregoriancalendar class in C:

 01: Using System; 02:  Using Java. util; 03:  04:  Class  Program05: { 06:    Static void Main () 07: { 08:      VaR Dt = New Gregoriancalendar (1582, 9, 4 ); 09:      For ( VaR I = 0; I <12; I ++) 10: { 11:        Console . Writeline (Dt. gettime ()); 12: DT. Add ( Calendar . Day_of_month, 1 ); 13: } 14: }15: }

Note that this program must reference vjslib. dll. The running result of this program is as follows:

Thu Oct 04 00:00:00 GMT + 08:00 1582tue Sep 25 00:00:00 GMT + 08:00 1582wed Sep 26 00:00:00 GMT + 08:00 1582thu Sep 27 00:00:00 GMT + 08:00 hour Sep 28 00:00:00 GMT + 08:00 1582sat Sep 29 00:00:00 GMT + 08:00 1582sun Sep 30 00:00:00 GMT + 08:00 1582mon Oct 01 00:00:00 GMT + 08:00 hour Oct 02 00:00:00 GMT + 08:00 1582wed OCT 03 00:00:00 GMT + 08:00 hour Oct 04 00:00:00 GMT + 08:00 1582tue Sep 25 00:00:00 GMT + 08:00 1582

We can see that July 22, October 4, 1582 is indeed a Thursday. But how will the next day become Tuesday, September 25, 1582? It seems that Microsoft's vjslib. dll is faulty.

The. NET Framework base class library contains the system. Globalization. gregoriancalendar class, but this class cannot properly process the July October 4, 1582.

(If the user specifies whether to use the Confucianism or the Gregorian calendar, the system. Globalization. gregoriancalendar class on the. NET platform still works properly. For more information, see "Programming Language (I) In ubuntu. ---- Reference comments from the 13th floor)

In C, data structures and functions related to date and time are located in time. H, starting from January 1, 1900. Therefore, the date of January 1, 1582 cannot be expressed.

In the C ++ language and its standard library, I have not found any content related to Gregorian calendar. However, the famous C ++ boost library contains the Gregorian date system.

In Ruby, date. RB-Date and Time library can correctly process Gregorian calendar.

In python, datetime-Basic Date and Time types can correctly process Gregorian calendar.

In Perl, Date: calc-Gregorian calendar date calculations can correctly process Gregorian calendar.

References
    1. Gregorian calendar
    2. Julian calendar
    3. . NET Framework Class Library: Calendar class
    4. . NET Framework Class Library: gregoriancalendar class
    5. . NET Framework Class Library: juliancalendar class
    6. . NET Framework Class Library: chineselunisolarcalendar class
    7. Visual J # redistributable packages
    8. JAVA. util. gregoriancalendar
    9. JAVA. util. gregoriancalendar (Chinese)
    10. C Library: ctime (time. h)
    11. C Library: ctime (time. h): struct tm
    12. boost: Gregorian
    13. RUBY: date. RB-Date and Time library
    14. Python: datetime-Basic Date and Time types
    15. Perl: Date: calc-Gregorian calendar date calculations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.