How to display a DateTime with chosen date parts, but in the order of the FormatProvider?
- by Stephane
I want to display the date in the order that the culture provides, but with the elements I want only.
The DateTime.Tostring() method has a list of patterns that are very useful but I would like a very small change in it.
The CultureInfo used in the following the following code are chosen as example, I don't want to rely on a specific list of CultureInfo, if possible
var now = DateTime.Now;
string nowString = now.ToString("m", CultureInfo.GetCultureInfo("en-us"));
Console.WriteLine(nowString);
nowString = now.ToString("m", CultureInfo.GetCultureInfo("fr-FR"));
Console.WriteLine(nowString);
displays :
April 12
12 avril
I would like a pattern that display the abbreviation of the month and the day, but that keeps the correct order from the specified CultureInfo.
using the pattern "MMM dd" will always display the month's abbreviation first, followed by the day, breaking the french order for example.
Any way to achieve that without too much custom code?