Is the date formatting dependent on both the language and the calendar system?

I believe this question is very general for all programmers in all languages. It's somewhat blurry. First, there are locales that encapsulate cultural information and other things. I believe that these local objects also encapsulate date and time formatting information, i.e. How to display a date in Unicode Standard. For example, "yyyy-MM-dd'T'HH: mm: ssZ". Each country may have its own date and time formatting rules, so we are all happy with the locales, and users of our applications get the date + time formatted according to what is usually in their region.

But now, the really ugly part. There are calendars. Various calendars. Gregorian, as in the USA, Europe and some other countries, but there are also Hebrew, Jewish and Muslim calendars and more. Now these calendars are, of course, different. They divide the time period into units of different lengths, some may have 13 months, others may only have moon phases instead of Monday, Tuesday, Wednesday, etc. I really don't know, but I know that some of them seem very strange to those who are used to the Gregorian calendar.

But blurry now: who really influences date + time formatting? Locale? Calendar system? Both? And does the locale usually tell you which calendar system to use as a rule? How does the calendar system affect the locale and vice versa?

I've searched almost all day now for this topic and it seems heavy like a huge brick.

+2


source to share


3 answers


A typical OS will have date procedures using the Gregorian calendar according to the international convention.

The locale will decide how to format the date information and what language.



This does not stop the use of other calendar systems regardless of the OS date functions, but does international trade require a common calendar to be agreed upon?

+2


source


The user may be from one area where he likes to use a particular calendar system, but his language is different from being on a remote site or somewhere else.



There are hundreds of other similar cases that people have to deal with if they need bulletproof formatting of calendars.

+1


source


I will try to explain how it works in .Net framewrk

The value stored in the DateTime variable is the number of ticks since a particular day. It depends on the calendar you are using. that is, today will have the same meaning regardless of the calendar.

The culture contains information about format and calendar strings for date printing.

When you ask the system to format a string, it will first do something like:

int year = culture.Calendar.GetYear(dt);
int month = culture.Calendar.GetMonth(dt);
int day = culture.Calendar.GetDay(dt);

      

the year will be 2009 in the gregorian calendar, but something else for other calendars.

The format string is then used to output the values ​​in the correct order, etc.

Because of this, the following code will not output the correct ISO date with the Hebrew locale.

dt.ToString("yyyy-MM-dd'T'HH:mm:ssZ");

      

The correct way is either

dt.ToString("yyyy-MM-dd'T'HH:mm:ssZ", CultureInfo.InvariantCulture);

      

or

dt.ToString("s");

      

The latter works because the environment automatically ignores the culture for the "s" format specifier (and a few others).

0


source







All Articles