[Solved] Convert string Time format to Time format [closed]


You can try ParseExact method to convert a custom string to a DateTime, then use ToString method to convert it to your desired string format.

 var result = DateTime.ParseExact("10:30AM", "hh:mmtt", CultureInfo.InvariantCulture)
                      .ToString("hh:mm:ss tt");
//result : "10:30:00 AM"

In the DateTime formatting you may remember these notes:

  • hh: hour part
  • mm: minute part
  • ss: second part
  • tt: represent AM/PM part

3

solved Convert string Time format to Time format [closed]