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)));
}
1条答案
按热度按时间v1l68za41#
您可能正在寻找ISO 8601周数(而不是其他周数系统之一)。
如果是这样的话,第一周总是1月4日的那一周,一周总是从星期一开始,在星期天结束。由此,您可以计算任何ISO周数的星期一。下面是一个紧凑的dart函数,可以做到这一点: