提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取当前即时和本地日期
//nowjava - 时代Java import java.time.Instant; import java.time.LocalDate; import java.util.Date; public class DateAndTime { public static void main(String[] args) { final Date date = new Date(); int secondDelta = 1; Instant timestampNew = Instant.now(); System.out.println("timestamp instant: " + timestampNew); timestampNew = Instant.now().minusSeconds(1); System.out.println("timestamp instant: " + timestampNew); System.out.println("raw Date: " + date); //deprecato date.setSeconds(date.getSeconds() - secondDelta); System.out.println("getSeconds(): " + date.getSeconds());/*from n o w j a v a . c o m - 时 代 Java*/ System.out.println("date dopo SecondDelta: " + date);