What's wrong with this date behavior in C #?

If I output a formatted date like this:

DateTime.Parse("2010-06-02T15:26:37.789 +01:00").ToString("HH:mm:sszzz")

I am getting the expected result:

15:26:37+01:00

However, if I parse the same date, convert to UTC and output in the same format as in the following format:

DateTime.Parse("2010-06-02T15:26:37.789 +01:00").ToUniversalTime().ToString("HH:mm:sszzz")

I get this:

14:26:37+01:00

Now these two dates, local and UTC versions, should be exactly the same, but the displayed text represents two different times.

Why is this?

EDIT

To clarify, I expected the time in UTC to be 14:26:37 when the DST item is removed by UTC. I didn't expect it to still have an offset. The above two times are not equivalent, whereas 15: 26: 37+ 01:00 and 14: 26: 37+ 00:00 .

+2


a source to share


3 answers


Ok now now as an answer: MSDN explains "zzz" like this:

With DateTime values, the "zzz" custom format specifier is the signed offset of the local system time zone from UTC , measured in hours and minutes. This does not reflect the value of the DateTime.Kind property. For this reason, the "zzz" format specifier is not recommended for use with DateTime values.



Help me. English is not my native language, but I read that as "zzz" is a machine offset, not related to the DateTime value at all. So - yes, it will be the same.

+6


a source


Your timezone for your region is probably UTC + 1. Check the result after .ToUniversalTime (), it should be 14:26 (UTC + 1-1 = UTC).



0


a source


June is in summer time. UTC does not provide daylight saving time.

Strange ... or not. If you change the month from June to January, it will be the same!

As I said, summer savings !!!

0


a source







All Articles