集册 Java实例教程 获取机器时间戳

获取机器时间戳

欢马劈雪     最近更新时间:2020-01-02 10:19:05

451
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
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
         
展开阅读全文