Time Conversion

  • + 0 comments

    C#

    string am = "AM"; string pm = "PM";

        if (s.Contains(am))
        {
            if (s[0] == '1' && s[1] == '2')
            {
                string newTwentyFourStart = "00";
                return newTwentyFourStart + s.Substring(2, 6);
            }
            return s.Remove(8,2);
        }
        else
        {
            if (s[0] == '1' && s[1] == '2')
            {
                return s.Remove(8,2);
            }
            string newTwentyFourStart = (int.Parse(s.Substring(0,2))+12).ToString();
            return newTwentyFourStart + s.Substring(2, 6);
        }
    }