i have a string which is "26052014153850" it is in the format of date month year hour minute second. i want to convert this to date and time format but its showing string is not recognized as valid date and time
string result ="26052014153850";
DateTime dt = DateTime.ParseExact(result, "dd/MM/yyyy/HH/mm/ss", CultureInfo.InvariantCulture);
asked May 27, 2014 at 4:59
-
possible duplicate of convert datetime to date format dd/mm/yyyyRam Singh– Ram Singh2014年05月27日 05:09:15 +00:00Commented May 27, 2014 at 5:09
1 Answer 1
DateTime dt = DateTime.ParseExact
(result, "ddMMyyyyHHmmss", CultureInfo.InvariantCulture);
The format of the string representation must match the specified format exactly.
Read this for more from MSDN.
answered May 27, 2014 at 5:00
3 Comments
user3596113
capital "HH" will make it count 24 hours, "hh" would only count till 12.
Farhad Jabiyev
@user2380844 Yes, I have changed. Good luck.
Adil
@FarhadJabiyev, adding description about the solution in the answer would make it easy to understand.
lang-cs