Instant 类是机器易读的时间信息,存放的是unix时间戳。
import java.time.Duration; import java.time.Instant; public class InstantExample { public static void main(String[] args) { Instant timestamp = Instant.now(); System.out.println("当前时间 = "+timestamp); Instant specificTime = Instant.ofEpochMilli(timestamp.toEpochMilli()); System.out.println("特定时间 = "+specificTime); //时间段 Duration thirtyDay = Duration.ofDays(30); System.out.println(thirtyDay); } }