简体   繁体   English

给定本地时区和目标时区,我如何找到目标的当前时间C#

[英]Given a local timezone and a target timezone how can I find the target's current time C#

I find many answers that are close but none that match my situation. 我发现许多答案很接近,但没有一个与我的情况相符。 We have agents in numerous international time zones answering phones for properties across the US and in some European nations. 我们在许多国际时区都有代理,负责接听美国和某些欧洲国家/地区的房地产的电话。 I know the properties' time zone as "EST", "PST, etc from a local database of property time zones. Of course I also know the agents' local times. 我从属性时区的本地数据库中知道属性的时区为“ EST”,“ PST”等。当然,我也知道代理的本地时间。

What method should I use and what time zone argument should I pass to determine the current time at the property? 我应该使用哪种方法以及应传递哪个时区参数来确定属性中的当前时间? Should I pass "EST" if the target property is on the US east coast and what if it is currently Daylight savings time? 如果目标物业在美国东海岸,我是否应该通过“ EST”?如果现在是夏令时,该怎么办? Would I then pass "EDT"? 然后我会通过“ EDT”吗? Must I spell out "Eastern Standard Time"? 我必须拼写“东部标准时间”吗? Is there an ordinal conversion such as 1 for EST... EST是否有序数转换(例如1)?

I would use TimeZoneInfo 's static method ConvertTime which Converts a time from one time zone to another. 我将使用TimeZoneInfo的静态方法ConvertTime ,该方法将时间从一个时区转换为另一个时区。 It receives a dateTime, a sourceTimeZone and a destinationTimeZone. 它接收dateTime,sourceTimeZone和destinationTimeZone。

Regarding the TimeZones, that is something that every OS knows, you can get the list of time zones from TimeZoneInfo, then those objects will know if they observe daylight or not. 关于TimeZones,每个OS都知道这一点,您可以从TimeZoneInfo获取时区列表,然后这些对象将知道它们是否遵守白天。 For that you can use the FindSystemTimeZoneById 为此,您可以使用FindSystemTimeZoneById

我将使用UTC并指定偏移量,例如: 2015-12-12T06:53:39-05:00表示当前是EST的2015-12-12上的01:53:39

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM