How to Get current Unix timestamp or milliseconds since epoch Dart or Flutter Programming| Flutter by Example

This article, Shows how to get the Current Timestamp or Unix Timestamp, or epoch timestamp in Dart and Flutter. We will use DateTime.milliseconds since epoch and DateTime.microsecondsSinceEpoch methods to return milli and macro seconds.

Epoch timestamp or Unix timestamp is a long number in milliseconds to refer to a time of a day. It is the Count of milliseconds elapsed since 1970-01-01 PST.

How to get the Current Epoch Timestamp in Dart/Flutter

Dart provides the DateTime class to provide Date and Time-related functions.

The now() method returns the DateTime object current date and time.

Here is an example to get the Current timestamp in Dart

void main() {
  print(new; //1646481543190000



DateTime.millisecondsSinceEpoch: Returns Unix timestamp in milliseconds. And 1 Second is equal to 1000 mill seconds DateTime.microsecondsSinceEpoch: Returns Unix timestamp in microseconds seconds and 1 second = 1000000 Microseconds