Java Data Type How to - Add one hour to Instant








Question

We would like to know how to add one hour to Instant.

Answer

import java.time.Instant;
import java.time.temporal.ChronoUnit;
/*from ww w .j  av a 2 s . c  om*/
public class Main {

  public static void main(String[] args) {
    Instant timestamp = Instant.now();
    System.out.println(timestamp);
    System.out.println(timestamp.plus(1, ChronoUnit.HOURS));

  }
}

The code above generates the following result.