java.util.Calendar
Calendar cal = Calendar.getInstance();// remove next line if you're always using the current time.cal.setTime(currentDate);cal.add(Calendar.HOUR, -1);Date oneHourBack = cal.getTime();
java.util.Date
new Date(System.currentTimeMillis() - 3600 * 1000);
org.joda.time.LocalDateTime
new LocalDateTime().minusHours(1)
Java 8:java.time.LocalDateTime
LocalDateTime.now().minusHours(1)
Java 8 java.time.Instant
// always in UTC if not timezone setInstant.now().minus(1, ChronoUnit.HOURS));// with timezone, Europe/Berlin for exampleInstant.now() .atZone(ZoneId.of("Europe/Berlin")) .minusHours(1));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)