-1

I want to change time 02:21:22 into 2 hours 21 minutes 22 seconds. How can I do this in flutter?

  • 3
    Does this answer your question? [How do I format a date with Dart?](https://stackoverflow.com/questions/16126579/how-do-i-format-a-date-with-dart) – Abbas Jafari Jun 10 '21 at 13:29

3 Answers3

0

If it is a string you can use split method using delimeter : and then appending hours minutes and seconds to the result

Ashutosh Patole
  • 926
  • 1
  • 7
  • 23
0

You can use the split method to achieve this.

 final String time = '02:21:22';
 final List<String> durations = time.split(':');

  print('${durations[0]} hours ${durations[1]} minutes ${durations[2]} seconds');
  // Prints 02 hours 21 minutes 22 seconds
quoci
  • 2,940
  • 1
  • 9
  • 21
0

You can try something like this.

var formatTime  = myTime.replaceFirst(':',' Hours ').replaceFirst(':',' Minutes ') + ' Seconds';
print(formatTime); //02 Hours 21 Minutes 22 Seconds
Ibrahim Ali
  • 2,083
  • 2
  • 15
  • 36