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.
HHis 24-hours, with a leading zero for the hours0-9.His 24-hours without a leading zero for the hours0-9.- Using
His not ISO 8601-compliant. ISO 8601 requires 2-digit date and time components with leading zeroes.
- Using
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:
MandMMis months, not minutes.mandmmis minutes not months.- There are few (if any) reasons to ever use
m, so always usemm!
- There are few (if any) reasons to ever use
his 12-hour clock hours without a leading zero.- Whenever you use
hyou must usettto denote AM/PM, otherwise you'll have ambiguous output.
- Whenever you use
hhis 12-hour clock hours with a leading zero.- Avoid using
hhbecause (I believe) that today people expect two-digit times to be using a 24-hour clock. - As with
h, you must also usettto avoid AM/PM ambiguity.
- Avoid using