简体   繁体   中英

.NET date formatting

Consider:

Assert.Equal("11 Aug 2010", date.ToString(???);

Somehow ToString("d MMM yyyy") outputs "11 aug 2010". How can I make it to be Aug instead of aug ?

ToString("d MMM yyyy", CultureInfo.CreateSpecificCulture("en-US")

作品

In that case how about using ToTitleCase():

ToTitleCase() method is hidden treasure of .Net Framework hosted by the System.Globalization.TextInfo namespace and can be used as shown below:

string sentence = "this is a title case EXAMPLE sentence";
string formattedSentence = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(sentence.ToLower());

Will result in "This Is A Title Case Example Sentence"

I have this cheat sheet website that i have saved to my favourites

http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM