Reputation: 251
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)
Upvotes: 0
Views: 305
Reputation: 17732
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);
print(newDateTime.next(DateTime.friday));
Upvotes: 2