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