Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert From DateTime to unix timestamp in Flutter or Dart in general

Tags:

flutter

as you seen in the title i want to convert from DateTime to unix Timestamp in Flutter (Dart Lang).

i saw the static Method that can convert from unix timestamp to DateTime :

DateTime.fromMillisecondsSinceEpoch(unixstamp);

i need the reverse

datatime => unixstamp

Thanks in advance.

like image 504
Ahmed Mostafa Avatar asked Sep 03 '18 17:09

Ahmed Mostafa


People also ask

How do you get a Unix timestamp in darts?

DateTime time = DateTime. now(); time. millisecondsSinceEpoch; January 1st, 1970 at 00:00:00 UTC is referred to as the Unix epoch.


1 Answers

Darts DateTime has a property millisecondsSinceEpoch which should be what unix timestamp is as well.

DateTime.now().toUtc().millisecondsSinceEpoch
like image 65
Günter Zöchbauer Avatar answered Sep 22 '22 17:09

Günter Zöchbauer