How to convert time between timezones (UTC to EDT)?

后端 未结 4 1100
暗喜
暗喜 2020-12-17 16:37

I need to have a common function to convert UTC time to EDT. I have a server in India. An application in it needs to use EDT time for all time purposes.

I am using

4条回答
  •  無奈伤痛
    2020-12-17 17:15

    Eastern Daylight Time isn't the name of a "full" time zone - it's "half" a time zone, effectively, always 4 hours behind UTC. (There may be proper terminology for this, but I'm not aware of it.)

    Why would you want to use EDT for times which don't have daylight savings applied? If you want a custom time zone that always has the same offset to UTC, use TimeZoneInfo.CreateCustomTimeZone.

    Note that if you use get the Eastern Standard timezone (TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")) then that will still have daylight saving time applied appropriately (i.e. during summer).

    For example:

    TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
    
    // Prints True
    Console.WriteLine(tzi.IsDaylightSavingTime(new DateTime(2009, 6, 1)));
    // Prints False
    Console.WriteLine(tzi.IsDaylightSavingTime(new DateTime(2009, 1, 1)));
    

提交回复
热议问题