C# program to convert time from 12 hour to 24 hour format

CsharpProgrammingServer Side Programming

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

 Live Demo

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
raja
Published on 20-Aug-2018 14:01:13
Advertisements