2

I need to display a timestamp in HH:mm:ss in Flutter. I don't understand what how to get it working.

 Duration duration = new Duration(
      days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: timestamp);
  print(duration);

I currently get something like this:

flutter: 305:26:50.086000
Ciprian
  • 3,066
  • 9
  • 62
  • 98
  • 1
    `Duration duration = new Duration(milliseconds: timestamp);` why don't you just do that? what's the expected output of yours? – danish-khan-I Jul 20 '19 at 05:20
  • I think I tried that. I need HH:mm:ss – Ciprian Jul 20 '19 at 05:36
  • and how are you gonna do that?? you need a time from unixtime right or what? i tried your code and i get different results [here](https://dartpad.dartlang.org/0f9607ea2c72f7b6bcfbe9e78cca0bba) – danish-khan-I Jul 20 '19 at 05:42
  • I'm comparing two timestamps. One is start one is current. And I need to show how many days, hours, minutes, seconds have lapsed during the two – Ciprian Jul 20 '19 at 05:48
  • 2
    you could check this question : https://stackoverflow.com/questions/52713115/flutter-finding-difference-between-two-dates – diegoveloper Jul 20 '19 at 05:50
  • you need `Datetime` for this.. as @diegoveloper mentioned – danish-khan-I Jul 20 '19 at 05:53
  • @diegoveloper 's answer here https://stackoverflow.com/questions/52713115/flutter-finding-difference-between-two-dates is how this should be handled. – Ciprian Jul 21 '19 at 04:16

1 Answers1

11

You can just remove the micro seconds and get it to work like this

print(duration.toString().split('.')[0]);
Ajil O.
  • 6,562
  • 5
  • 40
  • 72