0

I have the following code which converts UTC to local date/time.

Dim Ticks = DateTime.Parse("2018-03-25T01:00:00.000Z").Ticks
Dim UtcDate As New DateTime(Ticks, DateTimeKind.Utc)
Dim LocalTime = UtcDate.ToLocalTime()

The result in the LocalTime variable should be 25/03/2018 02:00:00 but it's 25/03/2018 03:00:00, two hours difference instead of one. I have checked my local system time settings and the time zone is correctly set at (UTC+00:00) London.

Note that GMT conversion works correctly with this code, only BST has an issue.

What am I doing wrong?

  • What does [tag:binary-search-tree] have to do with this question? Don't just randomly accept tag suggestions. – Damien_The_Unbeliever Dec 28 '17 at 12:53
  • I typed bst and accepted without looking, removed now. –  Dec 28 '17 at 13:05
  • `DateTime.Parse("2018-03-25T01:00:00.000Z")` does not make it a GMT unless specified. For e.g. does `Console.WriteLine(DateTime.Parse("2018-03-25T01:00:00.000Z").Kind)` return utc? Try `DateTime.Parse("2018-03-25T01:00:00.000Z", null, DateTimeStyles.RoundtripKind)` to let .net assume it's kind is GMT. – shahkalpesh Dec 28 '17 at 13:29
  • @shahkalpesh the date/time string is UTC string. I'm trying to convert that UTC string into my local UK time, taking daylight saving into account. –  Dec 28 '17 at 14:21
  • @kaiyaq: It looks like a Utc string. How does .net know if it is utc? Does `DateTime.Parse("2018-03-25T01:00:00.000Z").Kind` return value similar to `DateTimeKind.Utc`? This is the reason there are other parameters to `Parse` which user can specify as to how the date is to be treated. – shahkalpesh Dec 28 '17 at 14:23
  • I thought this line was telling .Net it was UTC date/time: `Dim UtcDate As New DateTime(Ticks, DateTimeKind.Utc)` –  Dec 28 '17 at 14:37

0 Answers0