1

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)?

Eren G
  • 43
  • 8

2 Answers2

2

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)))
BJW
  • 925
  • 5
  • 15
1

Use the format() method

Map<String, TimeOfDay> zeiten = {"Montag": TimeOfDay(hour: 15, minute: 0)};
TimeOfDay time = zeiten["Montag"];
print('${time.hour}:${time.minute.toString().padLeft(2, '0')}');
JideGuru
  • 7,102
  • 6
  • 26
  • 48