Close

Java Date Time - Instant.now() Examples

Java Date Time Java Java API 


Class:

java.time.Instant

java.lang.Objectjava.lang.Objectjava.time.Instantjava.time.Instantjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static Instant now()

Obtains the current instant from the system clock.



public static Instant now(Clock clock)

Obtains the current instant from the specified clock.


Examples


package com.logicbig.example.instant;

import java.time.Instant;

public class NowExample {

public static void main(String... args) {
Instant i = Instant.now();
System.out.println(i);
}
}

Output

2017-05-01T20:57:32.709Z




package com.logicbig.example.instant;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;

public class NowExample2 {

public static void main(String... args) {
Instant i = Instant.now(Clock.system(ZoneId.of("America/Chicago")));
System.out.println(i);
}
}

Output

2017-05-01T20:57:34.818Z




See Also