Example usage for java.time Instant now

List of usage examples for java.time Instant now

Introduction

In this page you can find the example usage for java.time Instant now.

Prototype

public static Instant now() 

Source Link

Document

Obtains the current instant from the system clock.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant now = Instant.now();
    System.out.println(now);/*w w w.java 2 s.c  o m*/
    System.out.println(now.getEpochSecond());
    System.out.println(now.getNano());
}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.now();
    System.out.println(instant.getEpochSecond());

}

From source file:Main.java

public static void main(String[] argv) {
    Instant timestamp = Instant.now();
    System.out.println("What is value of this instant " + timestamp);
}

From source file:Main.java

public static void main(String[] args) {
    Instant i1 = Instant.now();

    long seconds = i1.getEpochSecond();
    System.out.println(seconds);/*from  w w w.j  a  v a 2 s  .c o  m*/
    int nanoSeconds = i1.getNano();
    System.out.println(nanoSeconds);
}

From source file:Main.java

public static void main(String[] args) {
    Date dt = Date.from(Instant.now());
    System.out.println(dt);
}

From source file:Main.java

public static void main(String[] args) {
    Instant t1 = Instant.now();
    long hours = 2;
    long minutes = 30;
    Instant t2 = t1.plus(hours, ChronoUnit.HOURS).plus(minutes, ChronoUnit.MINUTES);

    System.out.println(String.format("now %s and later %s", t1, t2));
}

From source file:Main.java

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

}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.now();
    Clock newClock = Clock.fixed(instant, ZoneId.systemDefault());

    System.out.println(newClock.instant());
}

From source file:Main.java

public static void main(String[] args) {
    Instant i = Instant.now();

    System.out.println(toDate(i));

}

From source file:Main.java

public static void main(String[] args) {
    Instant i1 = Instant.now();

    ZoneId usChicago = ZoneId.of("America/Chicago");
    OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(i1, usChicago);
    System.out.println(offsetDateTime);
}