-5

What format is the following date time string in? I need to read it in C#.

2010-09-29T02:40:00.2291503+05:30
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 4
    Looks like `ISO 8601`: https://en.wikipedia.org/wiki/ISO_8601 – Flat Eric Feb 09 '16 at 09:39
  • Did you try anything to parse the date? E.g. looking on https://msdn.microsoft.com/library/system.datetime.parse%28v=vs.110%29.aspx or http://stackoverflow.com/questions/5366285/parse-string-to-datetime-in-c-sharp? – MakePeaceGreatAgain Feb 09 '16 at 09:42
  • 1
    Parsing the format with `DateTime.Parse` works fine, did you even try this? – Jens Feb 09 '16 at 09:43
  • What is your question _exactly_? Do you wanna get which format of your string? That's not possible since there can be ambiguous situations for it. Do you wanna parse it to `DateTime` instead which you mean by _I need to read it in C#_? If so, what have you tried to solve your problem? It is totally unclear what you asking. – Soner Gönül Feb 09 '16 at 11:09

2 Answers2

1

You can parse the string by using DateTime.Parse(string)

DateTime.Parse("2010-09-29T02:40:00.2291503+05:30");
Jehof
  • 34,674
  • 10
  • 123
  • 155
1

This is the DateTime with RoundTrip

The "O" or "o" standard format specifier (and the "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK" custom format string) takes advantage of the three ways that ISO 8601 represents time zone information to preserve the Kind property of DateTime values:

  • The time zone component of DateTimeKind.Local date and time values is an offset from UTC (for example, +01:00, -07:00). All DateTimeOffset values are also represented in this format.

  • The time zone component of DateTimeKind.Utc date and time values uses "Z" (which stands for zero offset) to represent UTC.

  • DateTimeKind.Unspecified date and time values have no time zone information.


Here's the example of use of DateTime.Kind:

using System;

public class Example
{
   public static void Main()
   {
       DateTime dat = new DateTime(2009, 6, 15, 13, 45, 30, 
                                   DateTimeKind.Unspecified);
       Console.WriteLine("{0} ({1}) --> {0:O}", dat, dat.Kind); 

       DateTime uDat = new DateTime(2009, 6, 15, 13, 45, 30, 
                                    DateTimeKind.Utc);
       Console.WriteLine("{0} ({1}) --> {0:O}", uDat, uDat.Kind);

       DateTime lDat = new DateTime(2009, 6, 15, 13, 45, 30, 
                                    DateTimeKind.Local);
       Console.WriteLine("{0} ({1}) --> {0:O}\n", lDat, lDat.Kind);

       DateTimeOffset dto = new DateTimeOffset(lDat);
       Console.WriteLine("{0} --> {0:O}", dto);
   }
}
// The example displays the following output:
//    6/15/2009 1:45:30 PM (Unspecified) --> 2009-06-15T13:45:30.0000000
//    6/15/2009 1:45:30 PM (Utc) --> 2009-06-15T13:45:30.0000000Z
//    6/15/2009 1:45:30 PM (Local) --> 2009-06-15T13:45:30.0000000-07:00
//    
//    6/15/2009 1:45:30 PM -07:00 --> 2009-06-15T13:45:30.0000000-07:00
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142