Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "DateTime.Now" in the Gregorian format when client calendar is non-Gregorian?

How can I get DateTime.Now in Gregorian calender when client calendar is non-Gregorian?

My project is a Silverlight with C# code and client default calender is not predicted.

like image 284
Masoomian Avatar asked Sep 16 '12 05:09

Masoomian


People also ask

How do you write a Gregorian date?

MM/DD/YYYY - American style Gregorian date format. DD/MM/YYYY - European style Gregorian date format.

What is Gregorian date format example?

Gregorian date. This format of date corresponds to any of the industry or IBM standard date formats supported by DB2. For example, the International Organization for Standardization (ISO) format is CCYY-MM-DD. 2013-12-14 is equivalent to the calendar date December 14 th 2013.

How is the Gregorian calendar calculated?

The Gregorian calendar, like the Julian calendar, is a solar calendar with 12 months of 28–31 days each. The year in both calendars consists of 365 days, with a leap day being added to February in the leap years. The months and length of months in the Gregorian calendar are the same as for the Julian calendar.


1 Answers

A DateTime value has no format. Internally it's just a count of ticks since the epoch, 0001-01-01 00:00 in .NET. Formatting is when you call ToString.

Just use a different CultureInfo for the culture that has the calendar you want, e.g.

CultureInfo french = CultureInfo.GetCultureInfo("fr-FR");

String nowStr = DateTime.Now.ToString( french );

Use CultreInfo.InvariantCulture if you just to use a predictable Western culture with a Gregorian calendar.

like image 105
Dai Avatar answered Oct 03 '22 01:10

Dai