get date timestamp flutter' code example
Example 1: flutter date time to timestamp
DateTime currentPhoneDate = DateTime.now();
Timestamp myTimeStamp = Timestamp.fromDate(currentPhoneDate);
DateTime myDateTime = myTimeStamp.toDate();
print("current phone data is: $currentPhoneDate");
print("current phone data is: $myDateTime");
Example 2: flutter date time
var now = new DateTime.now();
var moonLanding = DateTime.parse(now);
moonLanding.year;
moonLanding.hour;
moonLanding.month;
moonLanding.year.toString() + '-' + moonLanding.month.toString() + '-' + moonLanding.day.toString()
############################ OR ###########################
import 'package:intl/intl.dart';
var dt = DateTime.now();
var newFormat = DateFormat("yy-MM-dd");
String updatedDt = newFormat.format(dt);
print(updatedDt);
var newDt = DateFormat.yMMMEd().format(dt);
print(newDt);
reference :
https: