Question

I try to convert a string date to a DateTime. I know my string is an ISO8601 format, with an offset time zone.

I try this :

DateTime date = DateTime.ParseExact(strDate,"yyyy-MM-dd'T'HH:mm:sszzz", CultureInfo.InvariantCulture);

But it does not work in every cases.

It works for a negative offset : 2013-12-11T14:36:00-01:00

It does'nt work (catch an exception) for a positive offset : 2013-12-11T14:36:00+01:00

Am I using DateTime.ParseExact in the correct way?

Thank you for your help.

Was it helpful?

Solution

The string you have provided works for me without any format specifications.

        DateTime d = DateTime.Parse("2013-12-11T14:36:00+01:00");
        Debug.Print(d.ToString());
        Debug.Print(d.ToUniversalTime().ToString());

You see, in the latter Print, it prints minus 1 hour, as you specified + 1 hour time zone.

OTHER TIPS

Argh, I didn't do an url-encoding of my char '+'...... :S

It is used by a REST web service, so when I send 2013-12-11T14:36:00%2B01:00, it works..!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top