How to change time zone for an asp.net application

前端 未结 6 980
一个人的身影
一个人的身影 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:50

    Better could be to create a customTimeZone

            public static DateTime DateNow()
            {
                DateTime utcTime = DateTime.UtcNow;
                TimeZoneInfo myZone = TimeZoneInfo.CreateCustomTimeZone("INDIA", new TimeSpan(+5, +30, 0), "India", "India");
                DateTime custDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, myZone);
                return custDateTime;
            }
    

提交回复
热议问题