0

Consider I have 2 times which are for different countires:

"2013/02/11 13:20:44" (Tehran possibly UTC+3:30 or UTC+2:30 due to day light saving)
"2013/02/11 15:20:44" (Abu Dhabi possibly UTC+4:00 or UTC+3:00 due to day light saving)

Question1: How can I accurately convert these times to Utc?

I want to mention that the day light saving is not a fixed information and may vary time to time and country to country.

For example in 2010 Iran had not day light savings for some political reasons.

Question2: Is there some trust-able place or web service with this information?

mehrandvd
  • 8,806
  • 12
  • 64
  • 111
  • You would probably want to have a look at https://code.google.com/p/noda-time/ – oleksii Jun 16 '14 at 11:26
  • 1
    Most of the information you are looking for can be found in [the timezone tag wiki](http://stackoverflow.com/tags/timezone/info). The short answer is: Use [TimeZoneInfo](http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx), or [Noda Time](http://nodatime.org). – Matt Johnson-Pint Jun 16 '14 at 16:43

2 Answers2

3

For .net application Time Zone information updates with Windows updates, so if you server always have latest updates, you won't have problems with time zones.

And if you need to convert time, you can use TimeZoneInfo class:

TimeZoneInfo.ConvertTime(new DateTime(2005, 6, 1), TimeZoneInfo.FindSystemTimeZoneById("Iran Standard Time"), TimeZoneInfo.Utc)

And if you need to, you can get AdjestmentRules for time zones:

TimeZoneInfo.FindSystemTimeZoneById("Iran Standard Time").GetAdjustmentRules();
Uriil
  • 11,948
  • 11
  • 47
  • 68
  • Yes, upvoted, so if he trusts the time zone info on his local .NET and OS installation, this is the way. Note that there is a method `TimeZoneInfo.ConvertTimeToUtc` as well. – Jeppe Stig Nielsen Jun 16 '14 at 11:48
  • Does it consider the day light savings too? What if we can't trust on OS? – mehrandvd Jun 16 '14 at 11:49
  • 1
    @mehrandvd Yes, it knows about day light savings. Well, if you can't trust OS. You will have to find another timezone info provider(here i can't advise), or create you own time zones for countries you need – Uriil Jun 16 '14 at 12:06
0

You could try using Noda Time

More detailed information can be found in this thread

Community
  • 1
  • 1
Fergmux
  • 932
  • 9
  • 13
  • http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers – Soner Gönül Jun 16 '14 at 11:30
  • I was only really answering Question 2, I don't have much experience with .net, thought this may be more useful than leaving them completely in the dark, every little helps. – Fergmux Jun 16 '14 at 11:34