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 t1 = Instant.now();
    long hours = 2;
    long minutes = 30;
    Instant t2 = t1.plus(hours, ChronoUnit.HOURS).plus(minutes, ChronoUnit.MINUTES);

    long minutesBetween = Duration.between(t1, t2).toMinutes();
    System.out.println(minutesBetween);
}

From source file:Main.java

public static void main(String[] args) {
    OffsetTime m = OffsetTime.ofInstant(Instant.now(), ZoneId.systemDefault());

    System.out.println(m);/*  w  w w  .ja v a 2s .  c  om*/

}

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

    Duration gap = Duration.ofSeconds(13);
    Instant later = t1.plus(gap);
    System.out.println(later);//from w w  w.  ja  v a  2 s .co m

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

From source file:Main.java

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);/*from   w  w w  .  j a  v a  2  s.c om*/

    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
}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    System.out.println(instant.equals(Instant.now()));

}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault());

    System.out.println(z);/*  w w w  . j  av a2 s .c  o m*/

}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    System.out.println(instant.isAfter(Instant.now()));

}

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.ofInstant(Instant.now(), ZoneId.systemDefault());

    System.out.println(o);/*www  .j  av  a  2 s .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    System.out.println(instant.isBefore(Instant.now()));

}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC);

    System.out.println(a);
}