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

DateTime.add() doesn't effectively add the requested amount of time

I have these small lines:

Timestamp timestamp = document.get("timestamp");
DateTime time = timestamp.toDate();
time.add(const Duration(hours: 3));
print(time);

And before adding hours this is time:
enter image description here

And after adding 3 hours its value is the same:
enter image description here

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

What can it be caused by?

>Solution :

If you check the documentation of the add method you will see that it’s not a setter, rather it returns a new DateTime so you need it to assign to a new value.

var threeHoursFromNow = time.add(const Duration(hours:3));
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