LocalDateTime remove the milliseconds
Truncate
You can drop anything less than seconds. Call LocalDateTime::truncatedTo
.
ldt = ldt.truncatedTo(ChronoUnit.SECONDS);
Simply set them to 0
:
myObj.setCreated(rs.getTimestamp("created").toLocalDateTime().withNano(0));
Sample/proof:
import java.time.LocalDateTime;public class DateTimeSample { public static void main(String[] args) { LocalDateTime ldt = LocalDateTime.now(); System.out.println(ldt); System.out.println(ldt.withNano(0)); }}
Output:
2015-07-30T16:29:11.6842015-07-30T16:29:11
Author's note: Although this is the accepted one, Peter Lawrey's answer is IMHO preferrable because it makes the intention more clear.