如何转换时区(UTC到美国东部时间)之间的时间? [英] How to convert time between timezones (UTC to EDT)?
问题描述
我需要有一个共同的功能,UTC时间转换为EDT。我在印度的服务器。在它的应用程序需要使用EDT时间所有的时间的目的。
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.
我使用.NET 3.5。
I am using .NET 3.5.
我发现这对其他一些论坛。
I found this on some other forum.
DateTime eastern = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(
DateTime.UtcNow, "Eastern Standard Time");
当我试图用陇东夏令时我得到了一个错误。
When i tried with "Easten Daylight Time" I got an error.
时区ID东部夏令时未在本地计算机上找到。
"The time zone ID 'Eastern Daylight Time' was not found on the local computer".
请与本或任何其他解决方案的帮助。
Please help with this or any other solution.
推荐答案
东部夏令时间是不名一个全时区 - 这是半的时间段,有效,比UTC始终为4个小时。 (有可能是这个正确的术语,但我没有意识到这一点。)
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.)
您为什么要使用EDT对于不具备夏令时间应用?如果你想总是有相同的偏移量UTC自定义时区,使用 的TimeZoneInfo .CreateCustomTimeZone
。
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
.
请注意,如果你用得到东部标准时区( TimeZoneInfo.FindSystemTimeZoneById( 东部标准时间)
),那么仍会有适当应用夏令时间(即夏季)
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).
例如:
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)));
这篇关于如何转换时区(UTC到美国东部时间)之间的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!