Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i convert a DateTime variable "2022-09-29T07:26:52.000Z" to seconds in dart flutter?

I have a variable in dart string and would like to convert it all to seconds or minutes….

String x = "2022-09-29T07:26:52.000Z"

I want the opposite of this code below

final newYearsDay =
    DateTime.fromMillisecondsSinceEpoch(1640979000000, isUtc:true);
print(newYearsDay); // 2022-01-01 10:00:00.000Z

I want to be able to get this back to seconds from the current timedate formart

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can convert your string to a datetime by using intl like this:

String x = "2022-09-29T07:26:52.000Z";
var dateTime = DateFormat('yyyy-MM-ddThh:mm:ss').parse(x);

and for get the number of milliseconds since the Unix epoch :

print("numbers= ${dateTime.millisecondsSinceEpoch}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading