質問

I am using following code to format my datum

ToString("MMMM dd, hh:mmtt", System.Globalization.CultureInfo.CreateSpecificCulture("en-UK")

It results in i.e. June 01, 8:34PM. I need only "PM" ("AM") be lowercase "pm" ("am"). What is the simplest method to achieve it?

Thanks!

役に立ちましたか?

解決

I think you're going to have to split the strings and join them together.

Also, you don't need to specify the culture if you're doing custom formatting. The culture is really for the standard formats.

So I would do something like the following

var curDate = DateTime.Now;
var dateString = curDate.ToString("MMMM dd, hh:mm") + curDate.ToString("tt").ToLower();

他のヒント

Try this

DateTime dt = new DateTime(2013, 3, 9, 16, 5, 7, 123); // put your datetime variable value at last paramter value.
String.Format("{0:t tt}", dt);  // "P PM" A.M. or P.M.

For lowercase you just need to use .ToLower().

Or you can find more information HERE

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top