How to convert date time format in a Razor view? [duplicate]
问题 This question already has answers here : Converting DateTime format using razor (9 answers) Closed 3 years ago . 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? 回答1: 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 :