Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class Main {

    public static void main(String[] args) {
        Instant t1 = Instant.now();
        Instant t2 = Instant.now().plusSeconds(12);
        long nanos = Duration.between(t1, t2).toNanos();
        System.out.println(nanos);

        Duration gap = Duration.ofSeconds(13); // 12000000000
        Instant later = t1.plus(gap);
        System.out.println(t1); // 2014-07-02T19:55:00.956Z
        System.out.println(later); // 2014-07-02T19:55:13.956Z

        System.out.println(ChronoUnit.MILLIS.between(t1, t2)); // 12000
    }
}