Date Time format in Flutter dd/MM/YYYY hh:mm

2020-02-27 23:40发布

问题:

By using this :

Text(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000).toString(), 

I am getting the type of format attached in the picture, however I was wondering if I could get it in dd/MM/YYYY hh:mm??

回答1:

If you use the intl package

final f = new DateFormat('yyyy-MM-dd hh:mm');

Text(f.format(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000)));


回答2:

final df = new DateFormat('dd-MM-yyyy hh:mm a');
 int myvalue = 1558432747;
  print(df.format(new DateTime.fromMillisecondsSinceEpoch(myvalue*1000)));

Output

21-05-2019 10:59 AM



回答3:

You can use date_format plugin available here https://pub.dartlang.org/packages/date_format

Then to convert,

formatDate(DateTime.now(), [dd, '/', mm, '/', yyyy, ' ', HH, ':', nn])


标签: dart flutter