cGetFormattedDate method

String cGetFormattedDate({
  1. String? format,
})

Formats a date string into the specified format.

format (optional): A string representing the desired date format. If not provided, it defaults to 'dd/MM/yyyy'.

Returns a formatted date string according to the specified format or the default format if no format is provided.

Example:

String date = '2023-09-13';
String formattedDate = date.cGetFormattedDate(format: 'MMMM d, y');
// Result: 'September 13, 2023'

Implementation

String cGetFormattedDate({String? format}) {
  try {
    final dateTime = DateTime.parse(this);
    return DateFormat(format ?? 'dd/MM/yyyy').format(dateTime);
  } catch (e) {
    return this;
  }
}