Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To change a DateTime Zone from one time zone to another, you need to convert the date and time from one time zone to UTC, and then convert it to the new time zone. Here are the steps:

  1. Determine the current time zone of the DateTime object. For example, if the DateTime is in Pacific Time (PT), the time zone is UTC-8:00.

  2. Convert the DateTime to UTC using the ToUniversalTime() method. For example, if the DateTime is 2022-01-01 12:00 PM PT, the UTC time would be 2022-01-01 8:00 PM (12:00 PM minus 8 hours).

  3. Convert the UTC time to the new time zone using the TimeZoneInfo.ConvertTimeFromUtc() method. For example, if you want to convert the UTC time to Eastern Time (ET), you would use the following code:

DateTime utcTime = DateTime.UtcNow;
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, easternZone);
  1. The resulting DateTime object (easternTime in the example above) will have the new time zone.

Note that some time zones have different offsets depending on the time of year (such as daylight saving time), so it's important to consider this when converting time zones.