Dart - Converting Milliseconds Since Epoch (UNIX timestamp) into human readable time

Arthur Daniel picture Arthur Daniel · Jul 27, 2017 · Viewed 13.3k times · Source

Is there a good way to parse milliseconds since epoch (ex. 1486252500000 13 digits) formatted time into a human readable format?

Answer

Hadrien Lejard picture Hadrien Lejard · Jul 27, 2017

DateTime does have a named constructor for millisecond since epoch

https://api.dartlang.org/stable/1.24.2/dart-core/DateTime/DateTime.fromMillisecondsSinceEpoch.html

DateTime date = new DateTime.fromMillisecondsSinceEpoch(1486252500000)

If you want to convert it to human readable string, you can use intl package with the DateFormat class

import "package:intl/intl_browser.dart";

var format = new DateFormat("yMd");
var dateString = format.format(date);