0

I am receiving some data from web service and one of the fields is the Data object.

For instance, 2014-06-30T07:45:00+02:00 is the DateTime value.

When I try to parse this and get the time via

var time = DateTime.Parse("2014-06-30T07:45:00+02:00").TimeOfDay;

I get 8:45:00 instead of 7:45:00

Is it possible to ignore the daylight savings ? since web service returning the correct Date anyway ?

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
emre nevayeshirazi
  • 18,983
  • 12
  • 64
  • 81

1 Answers1

4

This should work:

var time = DateTimeOffset.Parse("2014-06-30T07:45:00+02:00").DateTime.TimeOfDay;

Jurgen Camilleri
  • 3,559
  • 20
  • 45
  • 2
    Var keyword is exactly the opposite of what you said. – Dmitrii Dovgopolyi Mar 23 '14 at 16:26
  • Eh, actually you'd use var if the return type is so obvious you'd feel silly for copying it, the only time you'd _not_ use var is for documentation purposes. – Cubic Mar 23 '14 at 16:28
  • Sorry but I disagree. While `var` can be used when you feel lazy/silly, I think it makes your code less readable. Also @DmitryDovgopoly, I do not see how it's the opposite of what I said. If you know what you're going to get in return, then I think you should specify it. Otherwise you have no choice but to use `var` e.g. with anonymous types. – Jurgen Camilleri Mar 23 '14 at 16:31
  • It still returns 8:45:00 – emre nevayeshirazi Mar 23 '14 at 16:32
  • See my update. I've removed the comment about the `var` keyword as I believe it's a matter of personal choice mostly. – Jurgen Camilleri Mar 23 '14 at 16:43