Reputation: 171
Please help me with this. After getting the timestamp from firebase, what it is displaying is this format 2019-04-16 12:18:06.018950
I am getting this as a stream from my firebase but I want it to be in this format 2019-04-16
just the date and not time.
Upvotes: 1
Views: 2366
Reputation: 7660
intl
packageString timeString = '2019-04-16 12:18:06.018950';
DateTime date = DateTime.parse(timeString);
print(DateFormat('yyyy-MM-dd').format(date)); // prints 2019-04-16
make sure to add the intl
package to the dependencies in your pubspec
intl: ^0.16.1
and also import it into your dart file
import 'package:intl/intl_browser.dart';
OR
split
method on the time stringString timeString = '2019-04-16 12:18:06.018950';
print(timeString.split(" ")[0]); // prints 2019-04-16
Upvotes: 3