Inspectopedia Help

Suspicious date format pattern

Reports date format patterns that are likely used by mistake.

The following patterns are reported:

  • Uppercase "Y", unless "w" appears nearby. It stands for "Week year" that is almost always the same as normal "Year" (lowercase "y" pattern), but may point to the next year at the end of December.

  • Uppercase "M" (month) close to "H", "K", "h", or "k" (hour). It's likely that a lowercase "m" (minute) was intended.

  • Lowercase "m" (minute) close to "y" (year) or "d" (day in month). It's likely that an uppercase "M" (month) was intended.

  • Uppercase "D" (day in year) close to "M", or "L" (month). It's likely that a lowercase "d" (day in month) was intended.

  • Uppercase "S" (milliseconds) close to "m" (minutes). It's likely that a lowercase "s" (seconds) was intended.

Examples:

new SimpleDateFormat("YYYY-MM-dd"): likely "yyyy-MM-dd" was intended.

new SimpleDateFormat("yyyy-MM-DD"): likely "yyyy-MM-dd" was intended.

new SimpleDateFormat("HH:MM"): likely "HH:mm" was intended.

New in 2020.1

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023