thisMonthEnd property

DateTime thisMonthEnd

本月的结束时刻,也是下个月的起始时刻

Implementation

static DateTime get thisMonthEnd {
  // 因为不确定本月有多少天,我们计算下个月的开始时间
  final now = DateTime.now();
  var year = now.year;
  var month = now.month;
  if (month == 12) {
    // 如果当前是12月份,下个月是明年1月
    year = year + 1;
    month = 1;
  } else {
    // 否则下个月等于本月 + 1
    month = month + 1;
  }

  return DateTime(year, month, 1, 0, 0, 0);
}