How to convert date time format in a Razor view? [duplicate]

烂漫一生 提交于 2019-12-25 07:37:19

问题


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:

[DisplayFormat(DataFormatString = "{0:d MMM \\'yy}")]
public DateTime YourDateTime { get; set }


来源:https://stackoverflow.com/questions/37524215/how-to-convert-date-time-format-in-a-razor-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!