MVC - UTC date to LocalTime

前端 未结 9 465
春和景丽
春和景丽 2020-12-28 10:07

We have a MVC project and I need to display a UTC date converted to users local time. In my model I am passing the UTC date and in the view I am trying to do the following:<

9条回答
  •  时光说笑
    2020-12-28 10:38

    All good answers. I did mine like this:

    @Html.DisplayFor(m=> m.SomeDate.ToLocalTime()
        .ToString(
            CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern 
            + " " 
            + CultureInfo.CurrentUICulture.DateTimeFormat.LongTimePattern))
    

提交回复
热议问题