MVC - UTC date to LocalTime

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

    Converting UTC Date Time To LocalDate Can be done using jquery as well. Main Benefit of doing it using jquery is in case you have hosted your website on azure. some methods given above will not work. Only one option will be left to be used that's using jquery / javascript. As Datetime.Now in case of your website is hosted on azure will return utc time for datetime.now.tolocaltime(). Please find below an example in jquery to convert UTC time to localdatetime.

    var date = new Date('2/8/2018 3:57:48 PM UTC');
    date.toString() // "Thu Feb 08 2018 21:27:48 GMT+0530 (India Standard Time)"
    

提交回复
热议问题