dart'; DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss"); Here we are going to use DateFormat class of flutter To get the current Time in AM/PM format.
You almost had it right. You just did not use a named constructor:
void main() {
print(DateTime.now().millisecondsSinceEpoch);
}
Gives:
1351441456747
See the API documentation for more: https://api.dart.dev/stable/2.10.1/dart-core/DateTime-class.html
This is my solution
DateTime _now = DateTime.now();
print('timestamp: ${_now.hour}:${_now.minute}:${_now.second}.${_now.millisecond}');
Microseconds is also available natively from Dart: (no need to import packages).
void main() {
print(new DateTime.now().microsecondsSinceEpoch);
}
output:
1591457696860000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With