Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String to Date parsing in C#?

I have a data string 'yyyymmddhhmmss' example: '20101001151014', how Do I parse this to date in C#?

like image 413
Bart Avatar asked Feb 26 '26 19:02

Bart


2 Answers

DateTime when = DateTime.ParseExact("20101001151014", "yyyyMMddHHmmss",
    CultureInfo.InvariantCulture);

Points to note: 24-hour hour is HH; 2-digit month is MM

like image 90
Marc Gravell Avatar answered Mar 01 '26 08:03

Marc Gravell


Use the DateTime.ParseExact method.

like image 34
Raj Avatar answered Mar 01 '26 09:03

Raj