getDayFromDate method
Returns the day name of the date provided in String
format.
If the date is in DateTime
format, you can convert it to String
DateTime().toString()
.
You can provide the locale
to filter the result to a specific language.
Defaults to 'en-US'.
Example
String date = '2021-10-23';
String day = date.getDayFromDate(); // returns 'Saturday'
String grDay = date.getDayFromDate(locale:'el'); // returns 'Σάββατο'
Implementation
String getDayFromDate({String locale = 'en'}) {
initializeDateFormatting(locale);
if (this.isBlank) {
return this;
}
var date = DateTime.tryParse(this);
if (date == null) {
return '';
}
return DateFormat('EEEE', locale).format(date).toString();
}