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

Current timestamp epcoh in Dart

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 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

Perl How to: Find a Given Variable String is numeric or not

Dart/Flutter: Check if String is Empty, Null, or Blank example

How to generate Unique Id UUID in Dart or Flutter Programming| Dart or Flutterby Example

How to Sort List of numbers or String in ascending and descending in Dart or Flutter example

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

Dart Example - Program to check Leap year or not

Dart Example to count the number of digits in a number| Decimals Count in Dart