DateTime? myLocalTime = Convert.ToDateTime("07/17/2016 12:28 PM");
Console.WriteLine(myLocalTime);
string givenTz = "Central";
DateTime? resultUtc = ConvertDateTimeToUtc(myLocalTime, givenTz);
Console.WriteLine(resultUtc);
public static void Main2()
DateTime currentLocalDT = DateTime.Now.AddHours(-6);
Console.WriteLine("Local: {0}", currentLocalDT);
DateTime? convertedDate = currentLocalDT;
DateTime? convertedDate1 = DateTime.UtcNow;
TimeZone localZone = TimeZone.CurrentTimeZone;
var dt = DateTime.UtcNow;
Console.WriteLine("UTC: {0}", dt.ToLocalTime());
var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
Console.WriteLine(utcOffset.ToOffset(tz.GetUtcOffset(utcOffset)));
public DateTime? ConvertDateTimeToUtc(DateTime? localDateTime, string timeZone)
if(timeZone == null) { throw new Exception("Could not convert the datetime to UTC because the Timezone input was null."); }
zone = "Eastern Standard Time";
zone = "Central Standard Time";
zone = "Mountain Standard Time";
zone = "Pacific Standard Time";
throw new Exception(string.Format("Could not convert the provided timezone to a standard US timezone. ({0})", timeZone));
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(zone);
string tzNameAfterDaylightSavingTimeCheck = tz.IsDaylightSavingTime(Convert.ToDateTime(localDateTime)) ? tz.DaylightName : tz.StandardName;
DateTime? utcDateTime = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(localDateTime), tz);