Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter/Dart TimeOfDay object returns TimeOfDay(15:00) instead of only the time

i want to print the Time that i initialized manually but if i print it then i only get this here.

I/flutter (14375): TimeOfDay(15:00)

Here is my Code

Future<void> ausgabe(BuildContext context) async {
Map<String, TimeOfDay> zeiten = {"Montag": TimeOfDay(hour: 15, minute: 0)};
print(zeiten["Montag"]);

}

How can i only print 15:00 instead of TimeOfDay(15:00)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can either use:

TimeOfDay time = TimeOfDay(hour: 15, minute: 0);
print(time.format(context));

Or you can do that with DateFormat from the intl flutter package.

print(DateFormat("HH:mm").format(new DateTime(
    2000,
    1,
    1,
    time.hour,
    time.minute)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading