Get current date time from server and convert it into local time in c#
no need to know server time zone. if the server time setting is correct you can try this :
DateTime serverTime = DateTime.Now; // gives you current Time in server timeZone
DateTime utcTime = serverTime.ToUniversalTime(); // convert it to Utc using timezone setting of server computer
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, tzi); // convert from utc to local
to check it locally , change your computer timezone to match your server. then run the code. I check and it's working fine.
update:
the first two lines can be mixed into one line as below . that has a better performance :
DateTime utcTime = DateTime.UtcNow;