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) {

        // same time in millis
        Instant now = Instant.ofEpochMilli(1262347200000l);

        // native plusSeconds() method to add 10 seconds
        Instant nowPlusTenSeconds = now.plusSeconds(10);

        // no native support for units like days.
        Instant nowPlusTwoDays = now.plus(2, ChronoUnit.DAYS);
        Instant nowMinusTwoDays = now.minus(Duration.ofDays(2));

        System.out.println(nowPlusTenSeconds);
        System.out.println(nowPlusTwoDays);
        System.out.println(nowMinusTwoDays);
    }
}