I have myself a DateTime
variable of
7/11/2014
and I want to convert that date to display as
7th November 2014
What format do I use? I have tried ToLongDateString
but it misses the suffix of the day date.
I have myself a DateTime
variable of
7/11/2014
and I want to convert that date to display as
7th November 2014
What format do I use? I have tried ToLongDateString
but it misses the suffix of the day date.
I don't believe there's any direct support for ordinals ("st", "nd", "th") within .NET. If you only need to support English, I suggest you hard code it yourself. For example:
string text = string.Format("{0}{1} {2} {3}", dt.Day, GetOrdinal(dt.Day),
dt.ToString("MMMM"), dt.Year);
(Where you'd write GetOrdinal
yourself.) Note that this assumes you want exactly this format - different cultures (even within English) may prefer November 7th 2014
for example.
If you need to support all kinds of languages, it becomes very difficult - different languages have some very different approaches to ordinals.
Side-note: Even Noda Time doesn't handle this yet. I hope to eventually implement some CLDR support, which should in theory handle it for all locales. We'll see...