Search code examples
datetimefluttertimepicker

DateTime object always contain minute as 05 after converting from TimeOfDay in flutter


I using TimePicker for getting start time and end time. I'm using DateTime object in my data model. converting TimeOfDay to DateTime like this

  DateTime newTime = new DateTime(
                              startTime.year,
                              startTime.month,
                              startTime.day,
                              picked.hour,
                              picked.minute);

I print using this formmater

DateFormat timeFormat = new DateFormat("hh:mm a");

but newTime always contain minute as 05. DateTime.now() also print minute as 05 like 12:05 PM.


Solution

  • I'm trying to print using the wrong DateFormatter

    using

    DateFormat timeFormat = new DateFormat("hh:mm a");
    

    instead of

    DateFormat timeFormat = new DateFormat.jm();