I want to get a Date without time, but always failed. below is my codes:
long curLong = System.currentTimeMillis(); curLong = curLong - curLong % TimeUnit.DAYS.toMillis(1); Date date = new Date(curLong); System.out.println("date = " + date); the output:
date = Mon Oct 28 08:00:00 CST 2019 anyone knows why? Thank you
java.util.Daterepresents an instant in time. You should use thejava.timeAPI instead, such asLocalDate.LocalDate.now()?java.util.Datenorjava.sql.Date,java.util.Calendar, and all the related classes. Ignore all StackOverflow or internet advice that tells you to use them. Use only thejava.timeclasses, and only tolerate the above classes in legacy code.