Formatting Date And Time In Flutter During Return Type

74 views
Skip to first unread message

Koustubha Bharadvaj

unread,
Jan 1, 2020, 12:23:19 PM1/1/20
to Flutter Development (flutter-dev)
Hi,
I have created fun: HomeScreen() which extends to HomeScreenState().
I have used HomeScreenState() to return Timing And Date.
But the issue is I'm unable to format time for HH:MM (am or pm) and date to DD/MM/YYYY.
_currentTime(){
 
return "${DateTime.now().hour} : ${DateTime.now().minute}";
 
}
 _currentDate
(){
 
return "${DateTime.now().day}.${DateTime.now().month}.${DateTime.now().year}";
 
}

I want this to be in required format.

Andy Greenshaw

unread,
Jan 1, 2020, 12:45:05 PM1/1/20
to Koustubha Bharadvaj, Flutter Development (flutter-dev)
Use FateFormat


import 'package:intl/intl.dart';

DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);

 

From: flutt...@googlegroups.com on behalf of Koustubha Bharadvaj <bkous...@gmail.com>
Sent: Wednesday, January 1, 2020 5:23 pm
To: Flutter Development (flutter-dev)
Subject: Formatting Date And Time In Flutter During Return Type
 
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f1a155fe-e7e2-4a82-80a7-60c23979ca0b%40googlegroups.com.

Koustubha Bharadvaj

unread,
Jan 2, 2020, 12:31:11 PM1/2/20
to Flutter Development (flutter-dev)
Thanks Bro,
This is working up for me.

Koustubha Bharadvaj

unread,
Jan 2, 2020, 12:59:19 PM1/2/20
to Flutter Development (flutter-dev)
Can I get one more help?
I have created the complete flutter app now.
But i want it to auto refresh code, so that date and  time do change automatically...

Jean Paul Gotopo Maldonado

unread,
Jan 2, 2020, 5:27:09 PM1/2/20
to Flutter Development (flutter-dev)
Reply all
Reply to author
Forward
0 new messages