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

13,696

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

DateTime.now().toUtc().millisecondsSinceEpoch
Share:
13,696

Related videos on Youtube

Ahmed Mostafa
Author by

Ahmed Mostafa

i love computer programming language likes , PHP, MySQL, JavaScript, CSS, HTML, AngularJS

Updated on June 04, 2022

Comments

  • Ahmed Mostafa
    Ahmed Mostafa almost 2 years

    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.

  • f0xik
    f0xik over 4 years
    Unix timestamps are in seconds, so you'll need to divide that by 1000.
  • anthares
    anthares about 2 years
    ^ this should be the correct answer!