When I do a datetime.now() in Flutter, for example 1:7:6, it shows 1:7:6. We want this to be displayed as 01:07:06.
DateTime now = DateTime.now();
print('${now.year}/${now.month}/${now.day} ${now.hour}:${now.minute}:${now.second}')
result
2023/5/10 1:7:56
2
Answers
You can use:
DateFormat documentation: https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html
adding to the answer of @Alaindeseine you can also do it using toString().padLeft() method to pad the hours, minutes, and seconds with leading zeros if necessary:
Code