How get the name of the days of the week in Dart

Use 'EEEE' as a date pattern

 DateFormat('EEEE').format(date); /// e.g Thursday

Don't forget to import

import 'package:intl/intl.dart';

Check this for more info : https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html


in your pubspec.yaml file, dependencies section. add intl dependency like so :

dependencies:
  intl: ^0.16.0 // <-- dependency added here, remember to remove this comment
  // other dependencies . remove this comment too

more about intl dependency here : intl

This package provides internationalization and localization facilities, including message translation, plurals and genders, date/number formatting and parsing, and bidirectional text.

and then at the top of your dart file import :

import 'package:intl/intl.dart';

now you can use DateFormat as you wish, here is an example :

var date = DateTime.now();
print(date.toString()); // prints something like 2019-12-10 10:02:22.287949
print(DateFormat('EEEE').format(date)); // prints Tuesday
print(DateFormat('EEEE, d MMM, yyyy').format(date)); // prints Tuesday, 10 Dec, 2019
print(DateFormat('h:mm a').format(date)); // prints 10:02 AM

there are many formats you can use with DateFormat, more details found here : https://api.flutter.dev/flutter/intl/DateFormat-class.html

hope this helps. Thank you


You can just use .weekday method to find out the day . eg:

 DateTime date = DateTime.now();
 print("weekday is ${date.weekday}");

This will return the weekday number, for eg tuesday is 2 , as shown below

class DateTime implements Comparable<DateTime> {
      // Weekday constants that are returned by [weekday] method:
      static const int monday = 1;
      static const int tuesday = 2;
      static const int wednesday = 3;
      static const int thursday = 4;
      static const int friday = 5;
      static const int saturday = 6;
      static const int sunday = 7;
      static const int daysPerWeek = 7;