andersnm/ExcelNumberFormat

How is CultureInfo respected when formatting dates?

kikaragyozov opened this issue · 3 comments

I fail to grasp how NumberFormat.Format(DateTime, CultureInfo) respects the provided CultureInfo object in any way or fashion. It seems to always manage to convert the date in any provided CultureInfo, even if that format does not exist for it.

That begs the question - is there an example you can provide where something unexpected is produced, or an exception of some kind is thrown due to differences in the CultureInfo object?

Perhaps the same issue persists in NumberFormat.Format(string, CultureInfo) but I think I'm wrong on this.

Hi,

CultureInfo is used by the formatter to get month names, era names, date separator, decimal separator and number group separator.

Admittedly not extensively covered by tests, but at least there's one for date separators in different cultures:

Hi,

CultureInfo is used by the formatter to get month names, era names, date separator, decimal separator and number group separator.

Admittedly not extensively covered by tests, but at least there's one for date separators in different cultures:

If my goal is to simply use the date separators and what-have-you that's defined in the format we pass to NumberFormat.Format(string, CultureInfo), how could I accomplish this? Basically I wish my date to be formatted the way it is in Excel.

Hi @kikaragyozov,

Keep in mind that Excel formats data differently depending on the language settings of your operating system. F.ex if somebody creates a spreadsheet in the US with dates, thousands etc, it would look differently on my machine here in Europe.

The easiest is to just pass CultureInfo.InvariantCulture as the culture, this gives you data formatted like Excel in US. If your app has localization features, you may want to use a culture based on the current user's language selection like CultureInfo.CurrentUICulture