Create two label in form by name ISTTime and CSTTime which show time in IST and CST
{
TimeZone zone = TimeZone.CurrentTimeZone;
DateTime local = zone.TolocalTime(DateTime.Now);
#get time zone information
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
#get offset of the zone information
TimeSpan offset = tzi.GetUtcOffset(DateTime.UtcNow);
#Add offset to universal time
DateTime testDateTime = DateTime.UtcNow.Add(offset);
#display local and universal time in label
ISTTime.Text =local.ToString();
CSTTime.Text=testDateTime.ToString();
}
{
TimeZone zone = TimeZone.CurrentTimeZone;
DateTime local = zone.TolocalTime(DateTime.Now);
#get time zone information
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
#get offset of the zone information
TimeSpan offset = tzi.GetUtcOffset(DateTime.UtcNow);
#Add offset to universal time
DateTime testDateTime = DateTime.UtcNow.Add(offset);
#display local and universal time in label
ISTTime.Text =local.ToString();
CSTTime.Text=testDateTime.ToString();
}
No comments:
Post a Comment