Validate DateTime pattern

G

Guest

Hi,
How i can check if a string is a valid DateTime pattern?
In java i can use the class SimpleDateFormat that throw an exception when is
initialized with an invalid datetime pattern. There is any class in C# that i
can use?

"yyyyMMdd" --> Correct format pattern
"dd44fgfd" --> Incorrect format pattern

Thanks in advance
 
S

Shiva

Try DateTime.ParseExact(). If it throws exception then, then the string is
not in the expected format.

Hi,
How i can check if a string is a valid DateTime pattern?
In java i can use the class SimpleDateFormat that throw an exception when is
initialized with an invalid datetime pattern. There is any class in C# that
i
can use?

"yyyyMMdd" --> Correct format pattern
"dd44fgfd" --> Incorrect format pattern

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top