Get Last Month Date In Flutter / Dart

前端 未结 6 1175
故里飘歌
故里飘歌 2021-01-11 18:37

in flutter we can get current month using this

var now = new DateTime.now();
var formatter = new DateFormat(\'MM\');
String month = formatter.format(now);
<         


        
6条回答
  •  星月不相逢
    2021-01-11 18:48

    We can calculate both first day of the month and the last day of the month:

    DateTime firstDayCurrentMonth = DateTime.utc(DateTime.now().year, DateTime.now().month, 1);

    DateTime lastDayCurrentMonth = DateTime.utc(DateTime.now().year,DateTime.now().month+1,).subtract(Duration(days: 1));

    DateTime.utc takes in integer values as parameters: int year, int month, int day and so on.

提交回复
热议问题