none
"Central European Standard Time" Daylight save time changes. RRS feed

  • Question

  • In our project we are fetching the datetime for germany with the below code snippert

    DT_DateTime = System.TimeZoneInfo.ConvertTime(System.DateTime.Now,System.TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"));

    it works fine. I read in net that germany follows day light save time which is going to be end on 27th october for this year and clocks will be shifted. My question is whether the above code snippet still fetch the correct time even after the clock is shifted or is there any a generic code to achive this.

    Thursday, September 19, 2019 2:49 PM

Answers

  • Yes it will work. Time zones are fixed (relatively speaking), it is the time offset that changes. Each TZ that supports daylight savings has a DST and ST name. The Id you pass to the method is the Id of the TZ. That won't change unless the TZs are updated for some reason.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, September 19, 2019 5:38 PM
    Moderator

All replies

  • Yes it will work. Time zones are fixed (relatively speaking), it is the time offset that changes. Each TZ that supports daylight savings has a DST and ST name. The Id you pass to the method is the Id of the TZ. That won't change unless the TZs are updated for some reason.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, September 19, 2019 5:38 PM
    Moderator
  • If you are in a zone that supports Daylight Saving Time (DST), then, in the night of change (1 hour back) in your area, DateTime.Now will return the same time value twice. For example, 01:30 will happen two times.

    In this case, there is a reasonable suspicion that ConvertTime will not be able to interpret the source time. Maybe you should use UtcNow instead of Now.

    • Edited by Viorel_MVP Friday, September 20, 2019 5:19 AM
    Friday, September 20, 2019 5:09 AM