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.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

SuspiciousDateFormat
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Probable bugs

New in 2020.1

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024