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: Find a Given String is numeric or not

How to iterate loop Enum in Dart | Get Enum with index in Flutter By Example

Dart Enum comparison operator| Enum compareByIndex example| Flutter By Example

Dart tutorial examples/ Flutter By Examples

How to add Methods or Values to Enums in Dart | Flutter By Example

How to convert Double to Integer or Integer to double in Dart| Flutter By Example

How to: Enum to String in Dart | Print Enum name as String in Flutter By Example