This question already has an answer here:
- Converting DateTime format using razor 9 answers
I need to display a date time string in the following format in a Razor view:
24 Jun'16
how can I convert the string in a Razor view?
This question already has an answer here:
I need to display a date time string in the following format in a Razor view:
24 Jun'16
how can I convert the string in a Razor view?
Just like you normally would:
@Model.YourDateTime.ToString("d MMM \\'yy")
The \\
escapes the '
, since that is a preserved character. The rest is quite straightforward.
Another option is the use of display attributes with DisplayFor
:
[DisplayFormat(DataFormatString = "{0:d MMM \\'yy}")]
public DateTime YourDateTime { get; set }