Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm struggling to get code that would successfully convert this string to DateTime:
07/11/11 10h09mn25s


The "h", "ms" & "s" characters cause my normal conversion code to misinterpret my usual mapping characters. Is there a way (like a wild card) to ignore a certain character positions completely?

E.g. say * is my wildcard...
string dateTimeStr = "07/11/11 10h09mn25s"
DateTime.ParseExact(datetimeStr, "dd/MM/yy HH*mm**ss*", System.Globalization.CultureInfo.InvariantCulture);


Thanks!
Posted
Updated 6-Nov-11 21:55pm
v2

1 solution

The parse string includes an escape character, try:
C#
string s = "07/11/11 10h09mn25s";
DateTime dt = DateTime.ParseExact(s, "dd/MM/yy hh\\hmm\\m\\nss\\s", CultureInfo.InvariantCulture);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900