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

Flutter – get previous 5 minute from current time

I need to get the time at the previous 5 minute interval. For example, suppose the time is

03-04-2024 07:16 I want 03-04-2024 07:15
03-04-2024 07:24 I want 03-04-2024 07:20
03-04-2024 07:45 I want 03-04-2024 07:45

I am getting the current time like this

DateTime now = DateTime.timestamp();

But need to work it back. Do I just need to loop by removing a minute until a 0 or 5?

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 :

I believe this should work:

now = now.subtract(Duration(minutes: now.minute.remainder(5)));
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