public JsonResult DateTimeByStateAndCountry(string d, string state2, string country2, string state3, string country3) { DateTime dateTime; if (!DateTime.TryParse(d, out dateTime)) { return(Json("Not a valid date/time")); } var startTz = TimeZoneByStateAndCountry.Current.GetTimeZoneInfo(state2, country2, TimeZoneId.UTC); var destTz = TimeZoneByStateAndCountry.Current.GetTimeZoneInfo(state3, country3, TimeZoneId.UTC); var utcTz = DateTimeAndZone.FromLocal(dateTime, startTz); utcTz.SwitchTimeZone(destTz); var dateString = utcTz.Local.ToString("M/d/yyyy h:mmtt").ToLower() + " " + utcTz.TimeZoneShortName; if (startTz.Id == "UTC") { dateString += " (start country not found)"; } if (destTz.Id == "UTC") { dateString += " (dest country not found)"; } return(Json(dateString)); }
public JsonResult ConvertDateTime(string d, string startTz, string destTz) { DateTime dateTime; if (!DateTime.TryParse(d, out dateTime)) { return(Json(null)); } var utcTz = DateTimeAndZone.FromLocalAndShort(dateTime, startTz); utcTz.SwitchTimeZone(destTz); var dateString = utcTz.Local.ToString("M/d/yyyy h:mmtt").ToLower() + " " + utcTz.TimeZoneShortName; return(Json(dateString)); }