JanDV

Hi,

I need to format a string using the month and year codes. But is has to be culture aware. Unfortunately the default YearMonthPattern of DateTimeFormatInfo doesn't do the trick because it displays the months in full text. So I tried to provide a custom pattern, but then it isn't culture aware anymore.

Dim d As New Globalization.DateTimeFormatInfo
d.DateSeparator = "/"
d.YearMonthPattern = "MM/yy"

Console.WriteLine(dDate.ToString(d.YearMonthPattern, New Globalization.CultureInfo("en-US")))
Console.WriteLine(dDate.ToString(d.YearMonthPattern, New Globalization.CultureInfo("fr-BE")))

Does anybody have an idea how to solve this

Thanks,

Jan



Re: .NET Base Class Library Culture and DatePattern

nobugz

Try this:

foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.AllCultures)) {
if (info.IsNeutralCulture) continue;
string pattern = info.DateTimeFormat.YearMonthPattern;
pattern = pattern.Replace("MMMM", "M");
pattern = pattern.Replace("yyyy", "yy"); // Optional
Console.WriteLine(DateTime.Now.ToString(pattern));
}