Reputation: 394
I am from India and I have a shared server with GoDaddy in the US for hosting an ASP.net website.
When I Use DateTime.Now
property I get the time in US.
How can I change it to Indian time for whole my application?
Upvotes: 1
Views: 1828
Reputation: 241808
Using TimeZoneInfo
is the best approach:
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);
Upvotes: 4
Reputation: 44961
I don't believe there is a way to change the timezone for an application, but you could replace all instances of DateTime.Now with a static class method that gets the current date and then adjusts it for the desired time zone.
For example:
var dtDate = DateTime.UtcNow;
dtDate.AddHours(5);
dtDate.AddMinutes(30);
return dtDate;
Upvotes: 0