formatDateTime static method
String
formatDateTime(
- String time,
- DateFormat format,
- String? dateSeparate,
- String? timeSeparate,
- bool? isZH,
Implementation
static String formatDateTime(String time, DateFormat format, String? dateSeparate, String? timeSeparate, bool? isZH) {
if (isZH!) {
time = convertToZHDateTimeString(time, timeSeparate);
}
switch (format) {
case DateFormat.NORMAL: //yyyy-MM-dd HH:mm:ss
time = time.substring(0, "yyyy-MM-dd HH:mm:ss".length);
break;
case DateFormat.YEAR_MONTH_DAY_HOUR_MINUTE: //yyyy-MM-dd HH:mm
time = time.substring(0, "yyyy-MM-dd HH:mm".length);
break;
case DateFormat.YEAR_MONTH_DAY: //yyyy-MM-dd
time = time.substring(0, "yyyy-MM-dd".length);
break;
case DateFormat.YEAR_MONTH: //yyyy-MM
time = time.substring(0, "yyyy-MM".length);
break;
case DateFormat.YEAR: //yyyy
time = time.substring(0, "yyyy".length);
break;
case DateFormat.MONTH: //yyyy
time = time.substring(0, "MM".length);
break;
case DateFormat.DAY: //yyyy
time = time.substring(0, "dd".length);
break;
case DateFormat.MONTH_DAY: //MM-dd
time = time.substring("yyyy-".length, "yyyy-MM-dd".length);
break;
case DateFormat.MONTH_DAY_HOUR_MINUTE: //MM-dd HH:mm
time = time.substring("yyyy-".length, "yyyy-MM-dd HH:mm".length);
break;
case DateFormat.HOUR_MINUTE_SECOND: //HH:mm:ss
time = time.substring("yyyy-MM-dd ".length, "yyyy-MM-dd HH:mm:ss".length);
break;
case DateFormat.HOUR_MINUTE: //HH:mm
time = time.substring("yyyy-MM-dd ".length, "yyyy-MM-dd HH:mm".length);
break;
case DateFormat.ZH_NORMAL: //yyyy年MM月dd日 HH时mm分ss秒
time = time.substring(0, "yyyy年MM月dd日 HH时mm分ss秒".length - (timeSeparate == null || timeSeparate.isEmpty ? 0 : 1));
break;
case DateFormat.ZH_YEAR_MONTH_DAY_HOUR_MINUTE: //yyyy年MM月dd日 HH时mm分
time = time.substring(0, "yyyy年MM月dd日 HH时mm分".length - (timeSeparate == null || timeSeparate.isEmpty ? 0 : 1));
break;
case DateFormat.ZH_YEAR_MONTH_DAY: //yyyy年MM月dd日
time = time.substring(0, "yyyy年MM月dd日".length);
break;
case DateFormat.ZH_YEAR_MONTH: //yyyy年MM月
time = time.substring(0, "yyyy年MM月".length);
break;
case DateFormat.ZH_MONTH_DAY: //MM月dd日
time = time.substring("yyyy年".length, "yyyy年MM月dd日".length);
break;
case DateFormat.ZH_MONTH_DAY_HOUR_MINUTE: //MM月dd日 HH时mm分
time = time.substring("yyyy年".length, "yyyy年MM月dd日 HH时mm分".length - (timeSeparate == null || timeSeparate.isEmpty ? 0 : 1));
break;
case DateFormat.ZH_HOUR_MINUTE_SECOND: //HH时mm分ss秒
time = time.substring("yyyy年MM月dd日 ".length, "yyyy年MM月dd日 HH时mm分ss秒".length - (timeSeparate == null || timeSeparate.isEmpty ? 0 : 1));
break;
case DateFormat.ZH_HOUR_MINUTE: //HH时mm分
time = time.substring("yyyy年MM月dd日 ".length, "yyyy年MM月dd日 HH时mm分".length - (timeSeparate == null || timeSeparate.isEmpty ? 0 : 1));
break;
default:
break;
}
time = dateTimeSeparate(time, dateSeparate, timeSeparate);
return time;
}