formatDate static method
以指定格式解析日期
Implementation
static String formatDate(
dynamic value, [
String format = 'yyyy-MM-dd HH:mm:ss',
]) {
var dateTime = safeDate(value);
if (format.contains('yy')) {
String year = dateTime.year.toString();
if (format.contains('yyyy')) {
format = format.replaceAll('yyyy', year);
} else {
format = format.replaceAll(
'yy',
year.substring(year.length - 2, year.length),
);
}
}
format = _comFormat(dateTime.month, format, 'M', 'MM');
format = _comFormat(dateTime.day, format, 'd', 'dd');
format = _comFormat(dateTime.hour, format, 'H', 'HH');
format = _comFormat(dateTime.minute, format, 'm', 'mm');
format = _comFormat(dateTime.second, format, 's', 'ss');
format = _comFormat(dateTime.millisecond, format, 'S', 'SSS');
return format;
}