1

I'm trying to convert the following string to datetime. I've searched high and low and can't find the exact formats string and I don't want to resort to parsing it manually.

var dateString = "20110828T134108+0100";

All my attempts fail with FormatException.

2
  • What format strings have you tried? Commented Feb 24, 2012 at 16:29
  • I tried first to remove the timezone so the string became "20110828T134108" and tried DateTime.ParseExact(dateString, "yyyyMMdd'T'hhmmss",null) but with no luck Commented Feb 24, 2012 at 16:36

4 Answers 4

3

Have you tried this?

var date = DateTime.ParseExact( dateString
   ,"yyyyMMdd\THHmmsszzz"
   ,CultureInfo.InvariantCulture 
   );  

From MSDN:

If format is a custom format pattern that does not include date or time separators (such as "yyyyMMdd HHmm"), use the invariant culture for the provider parameter and the widest form of each custom format specifier. For example, if you want to specify hours in the format pattern, specify the wider form, "HH", instead of the narrower form, "H".

Sign up to request clarification or add additional context in comments.

Comments

0

The documentation on the format string is here: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

That should get you started. :)

Comments

0

try this format: "yyyyMMdd'T'HHmmss"

Comments

0

Have you tried this:

DateTime.ParseExact("20110828T134108+0100", "yyyyMMdd'T'HHmmsszzzz", CultureInfo.InvariantCulture);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.