All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2718.html Maven / Gradle / Ivy

The newest version!

The use of the Instant class introduced in Java 8 to truncate a date can be significantly faster than the DateUtils class from Commons Lang.

Noncompliant Code Example

public Date trunc(Date date) {
  return DateUtils.truncate(date, Calendar.SECOND);  // Noncompliant 
}

Compliant Solution

public Date trunc(Date date) {
  Instant instant = date.toInstant();
  instant = instant.truncatedTo(ChronoUnit.SECONDS);
  return Date.from(instant);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy