简体   繁体   中英

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.

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? Would I then pass "EDT"? Must I spell out "Eastern Standard Time"? Is there an ordinal conversion such as 1 for EST...

I would use TimeZoneInfo 's static method ConvertTime which Converts a time from one time zone to another. It receives a dateTime, a sourceTimeZone and a 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. For that you can use the FindSystemTimeZoneById

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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