Converting time to Military

后端 未结 6 1248
清歌不尽
清歌不尽 2021-01-11 12:40

In an attempt to turn a date with a format of \"mm/dd/yyyy hh:mm:ss PM\" into military time, the following replacement of a row value does not seem to take. Eve

6条回答
  •  春和景丽
    2021-01-11 13:24

    If you have this time: 07:12:02PM and you want this: 19:12:02PM, then this is the code for you!

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    class Solution {
    
        static string timeConversion(string s) {
           DateTime dateTime = DateTime.ParseExact(s, "hh:mm:sstt", 
            System.Globalization.CultureInfo.InvariantCulture); 
    
            return (dateTime.ToString("HH:mm:ss"));
        }
    
        static void Main(String[] args) {
            string s = Console.ReadLine(); 
            string result = timeConversion(s);
            Console.WriteLine(result);
        }
    }
    

提交回复
热议问题