format method

String format({
  1. String pattern = 'yyyy-MM-dd',
})

Formats the DateTime object into a string using the provided pattern. If no pattern is provided, 'yyyy-MM-dd' is used by default.

Example:

print(DateTime.now().format(pattern: 'MM/dd/yyyy')); // Output: "04/07/2023"

Implementation

String format({String pattern = 'yyyy-MM-dd'}) => DateFormat(pattern).format(this);