0

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?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325

1 Answers1

4

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 }
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325