Hey. I have, somehow, this string available “20100205 162206”. This is a date and time without any delimiter char.
I need this back as a DateTime in C#. What is the best way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use one of the overloads of DateTime.ParseExact and specify a custom DateTime format string:
What this does is specify an exact format string for your input. (Namely “year-month-day hour-minute-second” without the dashes.)
If your input will always come in in one way, you are safest to use the ParseExact function, because, if you recieve bad data, it allows you to “fail early” rather than operating on inconsistent data.