Question Parsing a complete date

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
I have dates from a data file that I need to parse. Here is an example of one of the dates and what I have so far:

DateTime.ParseExact("2013-01-26T02:43:55+0000","yyyy-MM-dd\THH:mm:ss",

As you can see, the date includes the timezone offset (the "+0000" part at the end). I am not sure how to add that to the format string, since the date format pages I found only showed how to include the timezone offset as -0, -00, or -00:00. First of all, I do not have a dash before the timezone offset (I have a +, which I assume I can add using \+), and second, I need 4 digits, not 1 or 2. I am also not sure what to put for the provider parameter of the ParseExact method. Can somebody help me here? Thanks.
 
Use "K" for parsing time zone information. "+0000" is valid input and means the specified time has zero offset from Utc.

The input you have there conforms to ISO 8601, so you actually don't need ParseExact, the Parse method will read it for any culture.
 
Thanks, I think that worked when I used just the Parse method, I guess I was just having trouble finding anywhere that gave an example that used +0000, they all seemed to use +00:00 or some other format. Thanks again!
 
Back
Top