I was importing internationalization for my app but I have a problem where I parse my String but it only returns the date and not the time. When I change the phone language, my format for the Date changes but my Time isn't showing.

This is when it is EN_US enter image description here

This is when it is EU(German) enter image description here

That works well but my time format is missing...

This is the default String from the API: enter image description here

Here is the code:

/// I set a variable that calls the locale of the phone language and changes according to the phone preference
final f = DateFormat.yMd(Localizations.localeOf(context).languageCode);

/// where I dispay time and date but only date is shown in the pictures above
Text('Time and date: ${f.format(DateTime.parse(apicall.dateCreated))}');

My questions are: How do I show the time and how can I swap between showing the Time first then the Date, and opposite, if I want to show the Date first then the Time? (example 18-May-21 11:10h and if I want to do this 11:10h 18-May-21) Thanks in advance for the help!


Solution 1: obywan

I suppose you should use DateFormat.jm().add_yMd(): this will show time first and then date. To swap it just use DateFormat.yMd().add_jm() More info here