MVC Razor gets the name of the month

I have the following code in my MVC 4 razor view that should use the DateTime property called modifiedDate and print the name of the month, i.e. Jan, Feb, etc. Instead of 1, 2.

@foreach (var post in Model.NewsList) { <li class="entry"> <p class="calendar"><em>@post.modifiedDate.Value.Month.ToString("mmm")</em></p> </li> } 

Any ideas how to do this?

Thanks.

+4
source share
1 answer

See Custom MMMM Format Specifier

Using:

 DateTime? date = DateTime.Now; date.Value.ToString("MMMM"); // Prints the Month name (eg May) 

Fixed:

 @foreach (var post in Model.NewsList) { <li class="entry"> <p class="calendar"><em>@post.modifiedDate.Value.ToString("MMMM")</em></p> </li> } 
+8
source

Source: https://habr.com/ru/post/1483189/


All Articles