提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Instant类表示基于机器时间的时间轴上纳秒的开始。
import java.time.Instant; import java.time.ZoneId;/** 来 自 n o w j a v a . c o m**/ import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; public class Main { public static void main(String[] args){ Instant timestamp = Instant.now(); System.out.println("The current timestamp: " + timestamp); //Now minus three days Instant minusThree = timestamp.minus(3, ChronoUnit.DAYS); System.out.println("Now minus three days:" + minusThree); ZonedDateTime atZone = timestamp.atZone(ZoneId.of("GMT")); System.out.println(atZone); /** 来 自 时 代 J a v a - N o w J a v a . c o m