简体   繁体   中英

how to convert string to time formatted in flutter

I have data from database "192624". how I can change the String format in flutter become time formatted. example "192624" become to "19:26:24" . I try using intl packages is not my hope result.

this my code

DateTime inputDate = inputDate;
    String formattedTime = DateFormat.Hms().format(inputDate);

in above is not working
I want result convert data("192624") to become "19:26:24". data time from database.

use this method

String a() {
var a = "192624".replaceAllMapped(
    RegExp(r".{2}"), (match) => "${match.group(0)}:");
var index = a.lastIndexOf(":");
a = a.substring(0,index);
return a;
}

Have you checked out this a answer :

String time;
// call this upper value globally 
  String x = "192624";
  print(x.length);
  x = x.substring(0, 2) + ":" + x.substring(2, 4)+":"+x.substring(4,x.length);
  time =x;
  print(x);

just globally declare the string and then assign the local String to global then call it in the ui

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM