Home > Blockchain >  I need a list of Date and time in "hh:mm a" format from the list the List<int> flutt
I need a list of Date and time in "hh:mm a" format from the list the List<int> flutt

Time:10-27

Here is the code below: The below list is

     List<int> startTimeInInt = [1665392445000, 1665403245000, 1665405045000, 1665406845000, 1665410445000, 1665419445000, 1665574255000, 1665747055000, 1665390645000]

startTimeInInt.forEach((element) {
            var time = DateTime.fromMillisecondsSinceEpoch(element);
            var newFormat = DateFormat("hh:mm a");
            var newTime = newFormat.format(time).toString();
            print("date and time --->  $newTime");
          });

How can I get newTime like this:

List<String> newTime = ["02:30 PM","05:30 PM","06:00 PM","06:30 PM","07:30 PM","10:00 PM","05:00 PM","05:00 PM","02:00 PM","03:00 PM","03:30 PM"]

CodePudding user response:

you can do as follows:

final formatter = DateFormat.jm();
  final startTimeInInt = [
    1665392445000,
    1665403245000,
    1665405045000,
    1665406845000,
    1665410445000,
    1665419445000,
    1665574255000,
    1665747055000,
    1665390645000
  ];
  final newTime = startTimeInInt.map((element) {
    final time = DateTime.fromMillisecondsSinceEpoch(element);
    return formatter.format(time);
  });
  print(newTime);
  • Related