c sharp convert string time into 24 hours time

83

c sharp convert string time into 24 hours time -

DateTime dateTime = DateTime.Now;
string strMinFormat = dateTime.ToString("hh:mm:ss tt");//12 hours format
string strMaxFormat = dateTime.ToString("HH:mm:ss tt");//24 hours format

c sharp convert string time into 24 hours time -

using System;

class Solution
{
    static string timeConversion(string s)
    {
        return DateTime.Parse(s).ToString("HH:mm");
    }

    static void Main(string[] args)
    {
        Console.WriteLine(timeConversion("01:00 PM"));
        Console.Read();
    }
}

c sharp convert string time into 24 hours time -

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"));
      }
   }
}

Comments

Submit
0 Comments