Вопрос

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