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 to get the day based on week number in flutter

So i have a json object which displays year, month and week of year:

{
  "year": 2021,
  "month": 8,
  "week": 31,
},
{
  "year": 2021,
  "month": 8,
  "week": 32,
}

My question is how can i iterate through the json object then convert the week of year into day of month where the day is the end of the week and then pass in the year, month and day of month into a DateTime object in flutter like this:

DateTime(2021,8,7)
DateTime(2021,8,14)

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 :

Multiply the week with a 7 to get the total number of days. Like

 int totaldays = week*7;
 final extraDuration = Duration(days: totaldays);
 final startDate = DateTime(2021);

  final newDateTime = startDate.add(extraDuration);

 print(newDateTime);
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