MVC - UTC date to LocalTime

前端 未结 9 472
春和景丽
春和景丽 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:50

    DateTime now = DateTime.UtcNow;
    DateTime localNow = TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);
    

提交回复
热议问题