DateTime AM/PM format convert to 24h format

10,796

Date and times are not internally stored with any format in mind.

When you want to display the date/time, you use a format string on the ToString method of the object. There are standard and custom format strings.

For 24 hours use:

string formatted24HourTime = myDateTime.ToString("HH:mm");
Share:
10,796

Related videos on Youtube

N.D
Author by

N.D

Updated on June 04, 2022

Comments

  • N.D
    N.D almost 2 years

    i have a DateTime which is in AM/PM format . I want to convert it to 24h format , how can i do it? thanks.

    • Maurício
      Maurício about 13 years
      What language are you using? What have you tried so far?
  • N.D
    N.D about 13 years
    thank you. I had a problem with getting the value from the DB but now it is ok, but if i want my datetime to be formated like YYYYMMDDHHmmss ? is there a format like this?
  • Oded
    Oded about 13 years
    @olia - I linked to both the standard and custom documents on MSDN. I suggest looking there.

Related