How to get dateTime from week number and year in dart Example,
year = 2021 week = 35 return startDate = 29-08-2021 endDate = 04-09-2021
How to get dateTime from week number and year in dart Example,
year = 2021 week = 35 return startDate = 29-08-2021 endDate = 04-09-2021
You may be looking for the ISO 8601 week number (and not one of the other week numbering systems).
If that is the case, week 1 is always the week with January 4th in it, and a week always begins on a Monday and ends on a Sunday. From that you can calculate the Monday for any ISO week number. Below is a compact dart function that does this:
DateTime mondayOfIsoWeek(int isoYear, int isoWeek) {
// ISO week 1 always has January 4th in it
final jan4 = DateTime(isoYear, 1, 4);
// look back to find the Monday of that week
final mondayBeforeOrOnJan4 = jan4.add(Duration(days: -(jan4.weekday - 1)));
// add weeks to arrive at the Monday of isoWeek
return mondayBeforeOrOnJan4.add(Duration(days: 7 * (isoWeek - 1)));
}