Monday, 29 February 2016

Convert UTC time to local time by timezones




Convert UTC time to specific time zone’s time

// list of timezones
var timezones = TimeZoneInfo.GetSystemTimeZones();

// choose your timezone to convert time
var convertedDateTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow,
                                                                               TimeZoneInfo.Utc, 
                                                  TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));

// choose your timezone time to utc time
var convertedDateTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow,
                                         TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"),
                                                                               TimeZoneInfo.Utc);

No comments:

Post a comment