0

I have a calendar and in the calendar events are added in here
Map<DateTime, List<EventStore>> get events => _events;

where EventStore is anotherClass like this,

class EventStore{
  String subject;
  String level;
  String room;
  EventStore({this.subject,this.level,this.room});
}

Now, I want to compare today's date in yyyy-mm-dd format with the calendar date format. And I also don't know how to see the calendar date format.
How do I compare today's date in yyyy-mm-dd format with the calendar date format? So that I can show all the events that are on the particular date anywhere in my app?
And can anybody say, what is the DateTime format in map,
Map<DateTime, List<EventStore>> get events => _events;

Aman Chaudhary
  • 802
  • 3
  • 10
  • 27

1 Answers1

0

DateTime objects don't contain a date format, it's technically a number of elapsed time since 01-01-1970 https://api.flutter.dev/flutter/dart-core/DateTime-class.html

You can compare DateTime objects using their attributes.

DateTime savedDateTime = getSavedDateFromServer();
DateTime now = DateTime.now();

bool isSameYear = savedDateTime.year == now.year;
bool isSameMonth = savedDateTime.month == now.month;
//etc.

If you want to group your objects by date I recommend you take a look at this: Flutter/Dart how to groupBy list of maps

Er1
  • 2,559
  • 1
  • 12
  • 24