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.

Current timestamp epcoh in Dart

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

How to get Current Epoch Timestamp in Dart/Flutter

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

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

Here is an example to get Current timestamp in Dart

void main() {
  print(new DateTime.now().microsecondsSinceEpoch); //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

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.

Related posts

Dart| Flutter How to: Read pubspec.yaml attributes (version) with examples

How to Create and build a Singleton Class Dart or Flutter example| Dart By Example

What is the difference between var and dynamic and final in dart?| Flutter By Example

How to: Check if Phone number is valid or not in Dart| Flutter By Example

Dart| Flutter How to read an image from a disk and resize a file

Dart/Flutter: How to write setter and getter fields or members variables in a class with Example

Dart| Flutter How to get extension name and MIME type of a file with example