Very Curious
Very Curious

Reputation: 891

ASP.NET: Date format

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!

Upvotes: 0

Views: 5027

Answers (2)

Smeegs
Smeegs

Reputation: 9224

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();

Upvotes: 3

nrsharma
nrsharma

Reputation: 2562

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

Upvotes: 1

Related Questions