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


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

Updated on: 22-Jun-2020

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements