How to convert the string "yyyy-MM-ddZ" to a date with .net?

I'm having problems converting a string in the format "yyyy-MM-ddZ" using VB.net.

For example, I have the line "2007-10-21Z".

Using CDate or TryParse comes out before 10/20/2007 instead of 10/21/2007.

I do not understand how Z affects the date string, so when analyzing it, the result is the day before.

From what I understand, Z indicates a zero time zone. But the date string has no time information. How it works?

+4
source share
4 answers

Try

DateTime.ParseExact ("2007-10-21Z", "yyyy-MM-ddZ", CultureInfo.InvariantCulture);

+6
source

It interprets the date as midnight Zulu (GMT), and then converts it back to the local time zone. If you are in the States, which will be from 15:00 to 19:00 on the previous day.

+8
source

Adding "Z" to the date indicates that the time is UTC . When you copy a TryParse date, it converts it to local time.

+4
source

Wow, this is interesting. I am trying to use C # DateTime.Parse ("2008-10-31"). ToString (); and the result is "10/30/2008 5:00:00 PM".

I can not wait for an answer!

0
source

All Articles