How to convert the time to am/pm ?
I have this output
I/flutter (17720): 9:00:00
I/flutter (17720): 11:00:00
I/flutter (17720): 12:00:00
This is what I have tried
final item = snapshot.data[index];
print("Time " + item['time'].toString());
DateTime dateTime = DateTime.parse(item['time'].toString());
print(DateUtil().formattedTime(dateTime));
DateUtil
String formattedTime(DateTime dateTime) {
return DateFormat().add_jm().format(dateTime);
}
Error
I/flutter (17720): Time 09:00:00
════════ Exception caught by widgets library ═══════════════════════════════════ The following FormatException was thrown building Tags(dirty, state: TagsState#b3a2f): Invalid date format 09:00:00
Use this code:
DateFormat('hh:mm a').format(DateTime.now());
According to the intl library, it states that a represents AM/PM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With