none
How to get DateTime from one or two digit hour format dynamically RRS feed

  • Question

  • If hour is two digit, "M/d hh:mm:ss tt" works fine. 

    string tmpStr = "12/08 11:52:00 PM";
    DateTime dt = DateTime.ParseExact(tmpStr, "M/d hh:mm:ss tt", CultureInfo.InvariantCulture);

    However, if hour is one digit, that format doesn't work.

    string tmpStr = "12/08 3:52:00 PM";
    DateTime dt = DateTime.ParseExact(tmpStr, "M/d hh:mm:ss tt", CultureInfo.InvariantCulture);
    How could I get DateTime dynamically in both case(one digit/two digit)?

    Saturday, December 9, 2017 12:53 AM

Answers