Format hour using single "H" return two digits
Closed this issue · 2 comments
Describe the bug
Format hour using single "H" return two digits.
To Reproduce
Add a minimal working example or, if not possible or available, any code which might help to reproduce the problem
import 'package:intl/intl.dart';
main() {
final DateTime dt = DateTime(2011, 12, 12, 2);
var formatter = DateFormat('H');
var formatted = formatter.format(dt);
print(formatted);
formatter = DateFormat('yy-H');
formatted = formatter.format(dt);
print(formatted);
formatter = DateFormat('h');
formatted = formatter.format(dt);
print(formatted);
formatter = DateFormat('yy-h');
formatted = formatter.format(dt);
print(formatted);
}
output:
02
11-2
2
11-2
System info
from https://dartpad.dev/
The skeletons such as H
are not meant to be of the same length as the output number, see the docs. You might want to look at https://pub.dev/documentation/convert/latest/convert/FixedDateTimeFormatter-class.html for fixed, locale-independent formatting.
@mosuem Thanks for the reply. I'm developing a locale-aware Excel number formatter, for example [$-484]mmmm dd yyyy h:mm AM/PM
-> Januar 01 2022 4:32 vorm.
. and the single 'H' test case failed. I will comment out that one because it's likely an uncommon use case.
However the documentation is a little confusing because it shows H is number, and for number type, the count of pattern means the minimum number of digits. Even the example for H shows "0", not "00".