7

In an application I'm writing I want to display the current date and time, in English, but also in other locales.

For example Russian, Arabic and Chinese.

// DateTime.ToLongDateString doesn't support a IFormatProvider parameter
DateTime.Now.ToString("dddd, d MMMM, yyyy", new CultureInfo("en-US"));
// "Wednesday, 7 August, 2013"

DateTime.Now.ToString("dddd, d MMMM, yyyy 'r.'", new CultureInfo("ru-RU"));
// "среда, 7 августа, 2013 r."

Works fine...

DateTime.Now.ToString("dddd٫ d MMM٫ yyyy", new CultureInfo("ar"));
// "الأربعاء٬ 30 رمضان٬ 1434"

Seems to work fine.

However... I'd like to show the numerals as (Eastern) Arabic numerals, not as Latin/Arabic numerals. Though this could of course be solved by doing a simple substitution ('٠‎' to '0', 1 to '١' etc).

But then there's Chinese:

DateTime.Now.ToString("yyyy年M月d日dddd", new CultureInfo("zh-CN"))
// "2013年8月7日星期三"

Chinese numerals seem to be quite a bit more complex than just doing a simple substitution; sometimes one character becomes 2. Next to that, The formatted date seems to show the current Gregorian date, not the current Chinese date.

So my question is:

A) Is there any localization functionality in .NET/C# to display numbers (specificly dates) in other numeralsystems?

B) Can i force .NET/C# to display dates in the Chinese (and possibly Japanese and other) calendars, as it seems to do with the Arabic calendar?

Amy
  • 154
  • 3
  • 9
  • `(new CultureInfo("zh-CN")).Calendar` is Gregorian, you may need a custom CultureInfo. – H H Aug 07 '13 at 19:02
  • 2
    Number substitution works like this: (1) various `ToString` functions return standard (0-9) numbers; (2) when displaying the string in number substitution-enabled host (e.g., in a WPF window), the numbers are _displayed_ in a national script transparently for you (BUT the thread's culture must be set to the national one), see [this question](http://stackoverflow.com/q/6239729/276994); (3) this features works currently for Arabic, Hindi and Thai languages only, so no automatic way for Chinese classic numerals. – Vlad Sep 21 '14 at 15:23

2 Answers2

1

Play with ToLongDateString()

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-CN");
var myDate = DateTime.Now.ToLongDateString();

value for myDate: 2013年8月7日

Konstantin
  • 3,254
  • 15
  • 20
  • Don't forget to save the previous culture and put it back afterwards, or strange things could start happening... :) – Amy Aug 08 '13 at 08:39
0

See these questions (and answers):

As to whether that will work with all languages? ...I wouldn't bet on it, especially in cultures like that of China where there are multiple ways and context-sensitive usage.

Community
  • 1
  • 1
Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135
  • 1
    I can't seem to get this to work :( `CultureInfo Arabic = new CultureInfo("ar");` `Arabic.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;` `DateTime.Now.ToString("dddd٬ d MMM٬ yyyy", Arabic);` `// "الأربعاء٬ 30 رمضان٬ 1434"` strangly enough: `string.Format(Arabic, "{0}", 1);` `"1"` – Amy Aug 07 '13 at 19:18