-1

I have the following DateTime string 2014-11-03 08:44:00:082467 Z

When I try to do c simple Convert.ToDateTime I got and error that it's not a recognized DateTime string.

I also tried what's suggested in the post here: DateTime.Parse("2012-09-30T23:00:00.0000000Z") always converts to DateTimeKind.Local

var date = DateTime.ParseExact("2012-09-30T23:00:00.0000000Z",
                                   "yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'",
                                   CultureInfo.InvariantCulture,
                                   DateTimeStyles.AssumeUniversal |
                                   DateTimeStyles.AdjustToUniversal);

But got the same error. What kind of DateTime string is this? and how can I convert it to a DateTime object? Also, it's not the currect time (I'm 2 hours before) - so I'm guessing it's some kind of universal time.

Thanks

Community
  • 1
  • 1
developer82
  • 13,237
  • 21
  • 88
  • 153

3 Answers3

1

It looks like ISO 8601 format.

DateTime.Now.ToString("o")

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Patrick Allwood
  • 1,822
  • 17
  • 21
1

This is the format that applies to your string, although it is not a valid string according to the ISO 8601 standard:

var date = DateTime.ParseExact("2014-11-03 08:44:00:082467 Z",
                               "yyyy-MM-dd' 'HH:mm:ss:ffffff' Z'",
                               CultureInfo.InvariantCulture,
                               DateTimeStyles.AssumeUniversal |
                               DateTimeStyles.AdjustToUniversal);

Dotnetfiddle

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
0

The two dates you provide in your question are not the same at all !

Assuming your question applies to the second, which looks like to be standard, the answer is :

string s = "2012-09-30T23:00:00.0000000Z";
var date = DateTime.ParseExact(s, "o", CultureInfo.InvariantCulture,
                                   DateTimeStyles.AssumeUniversal |
                                   DateTimeStyles.AdjustToUniversal);
Console.WriteLine(date);

(full working sample)

AFract
  • 8,868
  • 6
  • 48
  • 70