public static System.DateTime ToTimeZone(this System.DateTime dateTime, Constants.TimeZone fromZone = Constants.TimeZone.CentralStandardTime, Constants.TimeZone toZone = Constants.TimeZone.EasternStandardTime) { System.DateTime now = System.TimeZoneInfo.ConvertTimeToUtc( dateTime, System.TimeZoneInfo.FindSystemTimeZoneById( Extensions.TimeZoneInfo.GetTimeZoneString(fromZone))); return(System.TimeZoneInfo.ConvertTimeFromUtc( now, System.TimeZoneInfo.FindSystemTimeZoneById( Extensions.TimeZoneInfo.GetTimeZoneString(toZone)))); }
/// <summary> /// Get the registry ID string for the given time zone. /// </summary> /// <param name="timeZone">The target time zone from Constants.TimeZone.</param> /// <returns>The string that can be used with /// TimeZoneInfo.FindSystemTimeZoneById() for time zone convertions.</returns> public static string GetTimeZoneString(Constants.TimeZone timeZone) { return(Constants.TimeZones[timeZone]); }
/// <summary> /// Get the registry ID string for the given time zone. /// </summary> /// <param name="timeZone">The target time zone from Constants.TimeZone.</param> /// <returns>The string that can be used with /// TimeZoneInfo.FindSystemTimeZoneById() for time zone convertions.</returns> public static string GetTimeZoneString(Constants.TimeZone timeZone) { ValidateNoNulls(timeZone); return(Constants.TimeZones[timeZone]); }