firstDayOfMonth method Null safety

String? firstDayOfMonth(
  1. {String locale = 'en'}

Returns the first day of the month from the provided DateTime.

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'.


String date = '2021-10-23';
String day = date.firstDayOfDate(); // returns 'Friday'
String grDay = date.firstDayOfDate(locale:'el'); // returns 'Παρασκευή'


String? firstDayOfMonth({String locale = 'en'}) {
  if (this == null) {
    return null;
  if (this!.isEmpty) {
    return this;
  var date = DateTime.tryParse(this!);
  if (date == null) {
    return null;
  return DateFormat('EEEE', locale)
      .format(DateTime(date.year, date.month, 1))