alister james
alister james

Reputation: 13

How can I get day name from string date '22 May 2022' in flutter

I am a beginner in Flutter, I want to get day name [like Sunday] from a date, date i am getting from api which is basically a string like '22 May 2022'

How can i get that from this date '22 May 2022' ? Can anyone help me? any help should be appreciated

I have tried this but not working for me.

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

Upvotes: 1

Views: 3027

Answers (4)

MDias
MDias

Reputation: 59

String daysOfTheWeek = DateFormat('EEEE').format(DateTime.now());

// Sunday

Upvotes: 0

Sapto Sutardi
Sapto Sutardi

Reputation: 456

You can use it:

import 'package:intl/intl.dart';

//--------------------

final DateTime today = DateTime.now();

final DateFormat format1 = DateFormat('EEE');
final DateFormat format2 = DateFormat('EEEE');

print(format1.format(today)); // abbreviated, exp. : Sun, Mon, Tue, ...
print(format2.format(today)); // not abbreviated, exp. : Suday, Monday,...

Upvotes: 2

Zozo
Zozo

Reputation: 33

final dateName = DateFormat('MEd').format(DateFormat("DD MMMM yyyy").parse('22 May 2022'));

You can check there all format date https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html

Upvotes: 1

manhtuan21
manhtuan21

Reputation: 3465

Try this :

final dateName = DateFormat('EEEE').format(DateFormat("DD MMMM yyyy").parse('22 May 2022'));

Upvotes: 2

Related Questions