Reputation: 2097
I'm using
DateTime.Now.ToString("dddd dd MMMM yyyy",new CultureInfo(user.CultureCodeISO2)
For dates in dutch. Now my requirements changed and I need to support full dates in french and english aswell.
It seems to me like there is no generic solution that results in a correct date in all 3 languages ... especially the following tricky parts marked in bold
le 15 décembre 2012 | December 15, 2012
le 29 mars 2011 | March 29, 2011
le 1er avril 2011 | April 1, 2011
Do I really need to write a custom function that adds the le and changes the order of the format depending on the culture?
ToLongDateString() doesn't work for me, this results in e.g. "mercredi 31 décembre 2003" without the le
Upvotes: 1
Views: 996
Reputation: 108
I am not sure what your user object is and what it delivers in CultureCodeISO2. I suppose it is an int for the culture identifier.
As you see in the link below there is no pattern for an article. If you do want this article then you maybe need to declare your own format:
Custom Date and Time Format Strings
If I were you I would write an extension method calling the ToString method internally and adding the article depending on selected language.
public static string ToStringWithArticle(this DateTime dateTime, string format, IFormatProvider provider)
{
var dateTimeString = dateTime.ToString(format, provider);
if (provider == new CultureInfo("fr-BE") || provider == new CultureInfo("fr-FR"))
{
dateTimeString = "le " + dateTimeString;
}
return dateTimeString;
}
You guess what I mean?
Upvotes: 1