Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 829
Arthur Daniel Avatar asked Jul 27 '17 17:07

Arthur Daniel


People also ask

How do you convert epoch time to human readable?

Convert from epoch to human-readable datemyString := DateTimeToStr(UnixToDateTime(Epoch)); Where Epoch is a signed integer. Replace 1526357743 with epoch. =(A1 / 86400) + 25569 Format the result cell for date/time, the result will be in GMT time (A1 is the cell with the epoch number).

How do you convert milliseconds to time in darts?

DateTime to TImestampThe millisecondsSinceEpoch property of the DateTime class gives us the number of milliseconds since the “Unix epoch” 1970-01-01T00:00:00Z (UTC). This is the timestamp in milliseconds. If you want the timestamp in seconds, just divide the result by 1000.

How do you parse a timestamp to a DateTime in darts?

Your timestamp is in some local format. import 'package:intl/intl. dart'; var dmyString = '23/4/1999'; var dateTime1 = DateFormat('d/M/y'). parse(dmyString); var mdyString = '04/23/99'; var dateTime2 = DateFormat('MM/dd/yy').

What is milliseconds since epoch?

The number of milliseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC). This value is independent of the time zone. This value is at most 8,640,000,000,000,000ms (100,000,000 days) from the Unix epoch. In other words: millisecondsSinceEpoch.


1 Answers

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); 
like image 140
Hadrien Lejard Avatar answered Oct 05 '22 11:10

Hadrien Lejard