0

I have following list of date and values in list to convert from UTC to local time that is UTC + 1 during winter and UTC + 2 during summer.

Daylight saving time in Italy will begin at 2:00 am on Sunday, 31 March and will end at 3:00 am on Sunday, 27 October.

List with date and values

UTC_DATE              Value
10/27/2019 0:00         10
10/27/2019 1:00         10
10/27/2019 2:00         10
10/27/2019 3:00         10
10/27/2019 4:00         10
10/27/2019 5:00         10
10/27/2019 6:00         10
10/27/2019 7:00         10
10/27/2019 8:00         10
10/27/2019 9:00         10
10/27/2019 10:00        10
10/27/2019 11:00        10
10/27/2019 12:00        10
10/27/2019 13:00        10
10/27/2019 14:00        10
10/27/2019 15:00        10
10/27/2019 16:00        10
10/27/2019 17:00        10
10/27/2019 18:00        10
10/27/2019 19:00        10
10/27/2019 20:00        10
10/27/2019 21:00        10
10/27/2019 22:00        10
10/27/2019 23:00        10

How do I convert the date in the list to local time to show the results like shown below on 27th of October

LOCAL_DATE           Value
10/27/2019 0:00        10
10/27/2019 1:00        10
10/27/2019 2:00        10
10/27/2019 2:00        10
10/27/2019 3:00        10
10/27/2019 4:00        10
10/27/2019 5:00        10
10/27/2019 6:00        10
10/27/2019 7:00        10
10/27/2019 8:00        10
10/27/2019 9:00        10
10/27/2019 10:00       10
10/27/2019 11:00       10
 ........             ....
 ........             ....
10/27/2019 23:00       10

And convert the date in the list to local time to show the results like below list on 31st of march

LOCAL_DATE           Value
10/27/2019 0:00        10
10/27/2019 1:00        30

10/27/2019 3:00        10
10/27/2019 4:00        10
10/27/2019 5:00        10
10/27/2019 6:00        20
10/27/2019 7:00        10
10/27/2019 8:00        10
10/27/2019 9:00        10
10/27/2019 10:00       10
10/27/2019 11:00       10
 ........             ....
10/27/2019 23:00       10

I am trying with below code, but not able to generate the missing hour 2 AM to 3 AM:

 var timeZoneInfo = "Central Europe Standard Time";
    var results = list.Select(o =>  new
                {
                    LocalDate = TimeZoneInfo.ConvertTimeFromUtc(o.Date.Value, timeZoneInfo),
                    Value = o.Value
                }).ToList();
Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
mahesh
  • 3,067
  • 16
  • 69
  • 127
  • https://stackoverflow.com/questions/2961848/how-to-use-timezoneinfo-to-get-local-time-during-daylight-savings-time is likely the answer – Alexei Levenkov Nov 22 '19 at 04:11
  • I agree with the previous comment. See marked duplicate. That said, the code you posted doesn't appear valid. You need to pass a `TimeZoneInfo` object to the `ConvertTimeFromUtc()` method, not a `string` object as you have here. So, depending on what you _actually_ mean by _"not able to"_ it might just be that you need to fix the compile-time error in your code by looking up the correct `TimeZoneInfo` (examples also can be found in the marked duplicate) – Peter Duniho Nov 22 '19 at 05:45

0 Answers0