I cannot seem to be able to parse the date obtained from DateTime.now()
in the hh:mm:ss
format. When I do, I get the below error:
Uncaught Error: FormatException: Trying to read : from 2022-12-05 15:40:34.987 at position 5
This here is my code:
import 'package:intl/intl.dart';
void main() {
var now = DateTime.now();
DateFormat inputFormat = DateFormat('hh:mm:ss');
var current = inputFormat.parse(now.toString());
print(current);
}
I would like to know what I need to do to get the time in the mentioned format.
2
Answers
By using intl package
parse
used when you want to convertstring
todateTime
, but I assume what you want is convertingdateTime
(now) to string format. you need to useformat
like this: