Firstly, set the 12 hr format date.
DateTime d = DateTime.Parse("05:00 PM");Now let us convert it into 24-hr format.
d.ToString("HH:mm"));The following is the code to covert time from 12 hour to 24 hour format −
Example
using System;
namespace Demo {
public class Program {
public static void Main(string[] args) {
DateTime d = DateTime.Parse("05:00 PM");
Console.WriteLine(d.ToString("HH:mm"));
}
}
}Output
17:00