toDate method
String
toDate({
- String? format,
- String? local,
- TimeFormats? timeFormat,
- DateFormats dateFormat = DateFormats.dateDMCY,
- String? separator,
Converts the custom date to a formatted string.
The method provides flexibility for custom formatting options.
Parameters:
format
: Custom date and time format string.local
: Optional parameter to specify the locale for formatting.timeFormat
: Enum specifying the time format (e.g., hour, minute, second).dateFormat
: Enum specifying the date format (e.g., day, month, year).separator
: Separator string between date and time components.
Example:
DateTime myDate = DateTime.now();
String formattedDate = myDate.toDate(
dateFormat: DateFormats.dateDMCY,
timeFormat: TimeFormats.timeHMa,
separator: " at ",
);
print(formattedDate); // Output: "06-02-2024 at 03:45 PM"
Implementation
String toDate({
String? format,
String? local,
TimeFormats? timeFormat,
DateFormats dateFormat = DateFormats.dateDMCY,
String? separator,
}) {
if ((format ?? "").isEmpty) {
if (timeFormat.isUsable && dateFormat.isUsable) {
format = "${dateFormat.use}'${separator ?? ' '}'${timeFormat.use}";
} else if (timeFormat.isUsable) {
format = timeFormat.use;
} else {
format = dateFormat.use;
}
}
return Andomie.i.dateFormatter(format ?? "", local, _v);
}