Nil
Nil

Reputation: 133

What date format should be set to show am/pm in lower case?

I am developing the MVC 3 application. In the view I am displaying the name along with created date time. It displayed as a

Nick Moris 27-Mar-13 11:49 AM <--

but I want to display in

Nick Moris 27-Mar-13 11:49 am <--

I have write the below line of code in the partial class for the date time property.

   [DisplayFormat(DataFormatString = "{0:dd MMM yy hh:mm tt} ")]
   public System.DateTime CreateDateTime { get; set; }

and in the View I am using below code...

@Html.DisplayFor(ModelItem => item.CommentDateTime.ToString("dddd, MMMM d, yyyy a\\t h:mmtt"))

What changes I have to made in the date format ? It showing error.

Upvotes: 1

Views: 5668

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039050

You could format it in the view without using the DisplayFor helper:

@item.CommentDateTime.ToString("dd-MMM-yy hh:mm")  @item.CommentDateTime.ToString("tt").ToLower()

In this case you no longer need the DisplayFormat attribute on your view model.

Upvotes: 6

Related Questions