I want to check if a string is in yyyyMMddHHmmss
format in C#. What is the best way to do it.
Here I have tried with DateTime.TryParse
, but it always return false
.
string currentFileName = "Test_File_20190312122838";
string timestampValue = currentFileName.Substring(currentFileName.LastIndexOf('_')+ 1);
DateTime outDate = DateTime.Now;
if (DateTime.TryParse(timestampValue, out outDate)) // always return false
{
}
Note: Sometimes timestampValue
may contain normal text instead of a timestamp value.