Unix Timestamp in Dart
Dart's DateTime class uses milliseconds internally — just like JavaScript. Use DateTime.now().millisecondsSinceEpoch for milliseconds, or integer-divide by 1000 for seconds. Flutter and server-side Dart both use the same API.
Code Examples
Current timestamp (milliseconds)
DateTime.now().millisecondsSinceEpoch;
Returns milliseconds since epoch as an int. This is Dart's native epoch unit — analogous to JavaScript's Date.now(). A 13-digit number on current hardware.
Current timestamp (seconds)
DateTime.now().millisecondsSinceEpoch ~/ 1000;
Integer divide by 1000 to get seconds. The ~/ operator is Dart's truncating division — it discards the remainder rather than rounding.
Using microsecondsSinceEpoch (high precision)
DateTime.now().microsecondsSinceEpoch;
Returns microseconds since epoch as an int. Useful for profiling and benchmarking where millisecond precision isn't enough.
Convert timestamp back to DateTime
final dt = DateTime.fromMillisecondsSinceEpoch(ms, isUtc: true);
Reconstruct a DateTime from a millisecond timestamp. Pass isUtc: true to get a UTC DateTime. Omit it and you get a local-timezone DateTime.
Format DateTime as ISO 8601
DateTime.now().toUtc().toIso8601String();
toIso8601String() produces a string like 2024-02-22T00:00:00.000Z. Always call toUtc() first unless you want local time in the output.
Note
Dart's DateTime.millisecondsSinceEpoch returns milliseconds — the same as JavaScript's Date.now(). When integrating Dart/Flutter apps with backend APIs that expect seconds (Python, Go, Unix), remember to divide by 1000. The intl package provides rich formatting if you need locale-aware date strings.
Frequently Asked Questions
How do I get the current Unix timestamp in Dart?
Use DateTime.now().millisecondsSinceEpoch for milliseconds, or DateTime.now().millisecondsSinceEpoch ~/ 1000 for seconds. Dart uses milliseconds as its native epoch unit, just like JavaScript.
Does Dart use seconds or milliseconds for Unix timestamps?
Dart uses milliseconds natively — millisecondsSinceEpoch returns a 13-digit int. Most Unix systems and backend APIs (Python, Go, databases) use seconds (10-digit). When sending timestamps to a backend, divide by 1000 using integer division: ~/ 1000.
How do I get a Unix timestamp in Flutter?
Flutter uses the same Dart DateTime API. Call DateTime.now().millisecondsSinceEpoch for milliseconds or DateTime.now().millisecondsSinceEpoch ~/ 1000 for seconds. There's no platform-specific code required — it works identically on iOS, Android, and web.
How do I convert a Unix timestamp back to a DateTime in Dart?
Use DateTime.fromMillisecondsSinceEpoch(ms, isUtc: true). Pass isUtc: true to get a UTC DateTime. If you have a seconds timestamp, multiply by 1000 first: DateTime.fromMillisecondsSinceEpoch(seconds * 1000, isUtc: true).
What is microsecondsSinceEpoch in Dart?
DateTime.now().microsecondsSinceEpoch returns microseconds since epoch (a 16-digit int on current hardware). This is useful for benchmarking and profiling where millisecond precision isn't sufficient. For most API and database work, millisecondsSinceEpoch is preferred.
Main Epoch Converter
Use the homepage when you need epoch to date, date to epoch, or a full epoch converter
This Dart guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.