How to convert a dateTime variable to Mountain Date Format (MT)?

Basically, I want to convert the UTC date time to MT date time format. Any Leads?

Hi @laraiv.khan ,

  1. Use the ParseExact method of the DateTime structure to parse the dateTime variable using the original date format. For example, if the original date format is “MM/dd/yyyy hh:mm:ss tt”, you can use the following expression:dateTime = DateTime.ParseExact(dateTimeString, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)where dateTimeString is the string representation of the dateTime variable.
  2. Set the time zone of the dateTime variable to Mountain Standard Time (MST) using the TimeZoneInfo.ConvertTime method. For example, if you want to convert to Mountain Daylight Time (MDT), you can use the following expression:dateTime = TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time"), TimeZoneInfo.FindSystemTimeZoneById("Mountain Daylight Time"))
  3. Convert the dateTime variable back to a string representation using the desired format. For example, if you want to use the format “MM/dd/yyyy hh:mm:ss tt”, you can use the following expression:dateTimeString = dateTime.ToString("MM/dd/yyyy hh:mm:ss tt")

Thanks,

Hi @laraiv.khan, welcome back to the Community.

The following thread has the discussion related to the conversion of UTC to a specified timezone:

Hope this helps.
Best Regards.

Thanks @RajKumar_DC

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.