What is the difference in H:mm:ss and HH:mm:ss in time formats?

I am trying to figure out the time format used on my computer if it is 12hour format or 24hour format and found this solution :

Dim strFormat As String = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern 

The Result is yyyy'年'M'月'd'日' H:mm:ss

I am having confusion between this H:mm:ss and this HH:mm:ss

Is there any difference in the format of the time displayed?

1 Answer

Is there any difference in the format of the time displayed?

Yes.

  • HH is 24-hours, with a leading zero for the hours 0-9.
  • H is 24-hours without a leading zero for the hours 0-9.
    • Using H is not ISO 8601-compliant. ISO 8601 requires 2-digit date and time components with leading zeroes.

So if the current time is 0945h then H:mm will render 9:45.

So if the current time is 0945h then HH:mm will render 09:45.

So if the current time is 1945h then H:mm will render 19:45.

So if the current time is 1945h then HH:mm will render 19:45.


Other important notes:

  • M and MM is months, not minutes.
  • m and mm is minutes not months.
    • There are few (if any) reasons to ever use m, so always use mm!
  • h is 12-hour clock hours without a leading zero.
    • Whenever you use h you must use tt to denote AM/PM, otherwise you'll have ambiguous output.
  • hh is 12-hour clock hours with a leading zero.
    • Avoid using hh because (I believe) that today people expect two-digit times to be using a 24-hour clock.
    • As with h, you must also use tt to avoid AM/PM ambiguity.
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like