How to change time zone for an asp.net application

前端 未结 6 976
一个人的身影
一个人的身影 2020-12-31 03:43

I need to set default timezone for my ASP.NET to Asia/Dhaka or GMT+6 timezone. But i cannot find a way to change it globally. There is a lot of reference on Stackoverflow an

6条回答
  •  孤独总比滥情好
    2020-12-31 03:51

    Sorry there is no way in .NET to change the time zone globally.

    The only way you have is to change the timezone of your server or rewrite all of your code.

    The best practice is to not rely on the system time zone at all (never use DateTime.Now).

    You should handle all date as Utc dates and then convert to a specific zone when displaying them to users.

    Even if you manage to handle timezones in your ASP.NET application, there are still timezones on SQL Server, for example GETTIME funtion. If your application is entirely written in UTC, your SQL server function will work as well.

提交回复
热议问题