Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get number of days of all month in Dart/Flutter?

Tags:

flutter

dart

I am creating whole year calender, How to get numbers of days of month in Flutter? e.g., January -> 31, Fabruary -> 28/29(as per year), March -> 31 So on...

like image 556
Mital Joshi Avatar asked Nov 08 '19 07:11

Mital Joshi


Video Answer


1 Answers

Using date1.difference(date2).inDays is NOT correct. For some dates it will return incorrect results, like for DateTime(2020, 3). This is because the Duration is based on seconds calculations. And inDays implementation is build with assumption that days are always have the same number of seconds (_duration ~/ Duration.microsecondsPerDay) which is not true.

But instead of this you can just use:

DateTime(date.year, date.month + 1, 0).day
like image 96
Jacek Marchwicki Avatar answered Dec 21 '22 19:12

Jacek Marchwicki