Stephany said:
You specified 'Z' in the format string ("yyyy-MM-ddTHH:mm:ssZ")
therefore your value string MUST end with a 'Z' otherwise the call to
DateTime.ParseExact will fail. ParseExact means just that (it must macth
EXACTLY).
The problem is that Z apperently do effect the parsing.
result = DateTime.ParseExact("1999-12-01T23:59:59",
"yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
Console.WriteLine(result);
result = DateTime.ParseExact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
Console.WriteLine(result);
outputs:
01-12-1999 23:59:59
01-12-1999 18:59:59
Your post indicates that your time zone is 1 hour ahead of UTC which
means tht when it is 11:59:59 PM UTC then it is 12:59:59 AM the next day
in your time zone which is exactly the result you got.
To get the result you want, the format string should, as Arne points
out, be "yyyy-MM-ddTHH:mm:ssz", but your value string should be
"1999-12-01T23:59:59+0".
No.
result = DateTime.ParseExact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);
Console.WriteLine(result);
result = DateTime.ParseExact("1999-12-01T23:59:59+0",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);
Console.WriteLine(result);
outputs:
01-12-1999 23:59:59
01-12-1999 18:59:59
Arne