Search code examples
datetimeflutter

Flutter - Can´t format Datetime


The error is simple

import 'package:intl/intl.dart';

DateFormat.d().format(DateTime.now().toString())

Return

The method 'd' isn't defined for the class 'DateFormat'. Try correcting the name to the name of an existing method, or defining a method named 'd'.

Is clear what happen but how can i fix it?


Solution

  • Try use this to get a day of week (like at monday)

    Add dependency intl

    intl: ^0.16.0 // Or the last version
    

    Code:

    import 'package:intl/intl.dart';
    
    DateFormat.EEEE().format(DateTime.now())