Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top