convertTwoDigitsForDate static method

String convertTwoDigitsForDate(
  1. int date
)

Checks if the given integer represents a two-digit date, and returns it in a standardized format. If the integer is not two digits long, it prefixes a '0' to the date.

@param date The integer representation of the date to be checked and formatted. @return A string representing the date in a two-digit format, with a leading '0' if necessary.

Implementation

static String convertTwoDigitsForDate(int date) {
  if (date.toString().length != 2) {
    return "0$date";
  } else {
    return date.toString();
  }
}