For Developers

Unix Timestamp in Dart

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in Dart (and Flutter) — plus the microseconds-vs-milliseconds mixup in the standard library.

int ts = DateTime.now().millisecondsSinceEpoch;
int ms = 1750000000000;
DateTime date = DateTime.fromMillisecondsSinceEpoch(ms, isUtc: true);
DateTime date = DateTime.utc(2025, 6, 15, 12, 0, 0);
int ts = date.millisecondsSinceEpoch;

The Dart-specific pitfall

Dart's DateTime exposes both millisecondsSinceEpoch and microsecondsSinceEpoch, and because most external APIs — including plenty of Flutter backend services — deal in plain Unix seconds, it's easy to grab the wrong one or forget to divide by 1000. The second, quieter trap: DateTime.now() returns a value in the device's local timezone by default, not UTC, so a value stored from one user's phone and displayed on another's can disagree unless you explicitly convert with .toUtc() before persisting it.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading