formatDateTime static method

String formatDateTime(
  1. int value,
  2. String format,
  3. DateTimePickerLocale? locale,
  4. dynamic weekday,
)

Format datetime string

Implementation

static String formatDateTime(
    int value, String format, DateTimePickerLocale? locale, weekday) {
  if (format.length == 0) {
    return value.toString();
  }

  String result = format;
  // format year text
  if (format.contains('y')) {
    result = _formatYear(value, result, locale);
  }
  // format month text
  if (format.contains('M')) {
    result = _formatMonth(value, result, locale);
  }
  // format day text
  if (format.contains('d')) {
    result = _formatDay(value, result, locale);
  }
  if (format.contains('E')) {
    result = _formatWeek(weekday, result, locale);
  }
  // format hour text
  if (format.contains('H')) {
    result = _formatHour(value, result, locale);
  }
  // format minute text
  if (format.contains('m')) {
    result = _formatMinute(value, result, locale);
  }
  // format second text
  if (format.contains('s')) {
    result = _formatSecond(value, result, locale);
  }
  if (result == format) {
    return value.toString();
  }
  return result;
}