-1

I'm trying to convert time between two timezones, and found out an hour difference between US Eastern Standard Time to Western European Time Supposedly, USA Eastern Standard Time (EST) 2018 Jun-18 1PM should be Western European Time (WET) same day 6PM, but the result from c# ConvertTime is 7PM, I think I missed something for the daylight setting? Anyway, here's the code:

var str = "2018-07-09T13:00:00";
var dt = Convert.ToDateTime(str);
var SourceZoneValue = "Eastern Standard Time";
var DestinationZoneValue = "W. Europe Standard Time";


TimeZoneInfo sourceTimeZone = TimeZoneInfo.FindSystemTimeZoneById(SourceZoneValue);
TimeZoneInfo destinationTimeZone = TimeZoneInfo.FindSystemTimeZoneById(DestinationZoneValue);

DateTime localTime = TimeZoneInfo.ConvertTime(dt, sourceTimeZone, destinationTimeZone);
Console.WriteLine(localTime);

The outcome is 7PM instead 6PM, any idea? tks

Kishore
  • 653
  • 6
  • 16
Joe Lu
  • 2,240
  • 1
  • 15
  • 18
  • @dasblinkenlight DateTime, it's the first parameter required by the method. I suggest using `TimeZoneInfo.FindSystemTimeZoneById` before converting to make sure it's returning the right timezone. – Thadeu Fernandes May 29 '18 at 17:43
  • sorry guys, my fault, I updated my code – Joe Lu May 29 '18 at 17:46
  • 3
    Keep in mind that we are currently in Daylight saving, so EST != EDT. – UnhandledExcepSean May 29 '18 at 17:46
  • Does "Eastern Standard Time\Dynamic DST" return the same value? https://stackoverflow.com/questions/14149346/what-value-should-i-pass-into-timezoneinfo-findsystemtimezonebyidstring – UnhandledExcepSean May 29 '18 at 17:57
  • I get 6PM for "US/Eastern" and "Europe/Lisbon" ([demo](https://ideone.com/NOpp9F)). – Sergey Kalinichenko May 29 '18 at 17:57
  • so I should manually set SourceZoneValue = "Eastern Standard Time\Dynamic DST" in this case? and write a method to determine whether it is a daylight zone or not? or there's some class to help? tks – Joe Lu Jun 05 '18 at 13:22

1 Answers1

1

You want to convert from Eastern Standard Time to W. Europe Standard Time, say from New York to Amsterdam.

New York time zone is -5 GMT, and Amsterdam time zone is +1 GMT:

enter image description here

  • New York Daylight saving started 11 March 2018 and will end on 4 November 2018.
  • Amsterdam Daylight saving started 25 March 2018 and will end on 28 October 2018.

Your date is 18 June, so daylight saving does not affect the time difference, I would say 7 PM is the correct result.


Maybe W. Europe Standard Time is not the correct time zone that you are looking for? For example, for the UK time:

var britishZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137