logo

Java Instant now() 메소드

Java Instant 클래스의 now() 메소드는 시스템 시계에서 현재 순간을 얻는 데 사용됩니다.

Java Instant now() 메소드는 2개의 매개변수로 구성됩니다.

  • Java Instant now() 메소드
  • Java Instant now(시계시계) 방식

Instant now() 메서드는 시스템 UTC 시계를 쿼리하여 현재 순간을 가져옵니다.

Instant now(시계시계) 메서드는 지정된 지금을 쿼리하여 현재 시간을 가져옵니다.

통사론

 public Instant now() public Instant now(Clock clock) 

매개변수

시계 - 사용할 시계. null이 아닙니다.

반품

null이 아닌 현재 순간입니다.

null이 아닌 시스템 시계를 사용하는 현재 순간입니다.

Java Instant now() 메소드 예

실시예 1

 import java.time.Instant; public class InstantNowExample1 { public static void main(String[] args) { Instant instant = Instant.now(); System.out.println(instant.getEpochSecond()); } } 
지금 테스트해보세요

산출:

출력은 다음과 같습니다.

 1410134852 

실시예 2

 import java.time.Instant; public class InstantNowExample2 { public static void main(String... args) { Instant i = Instant.now(); System.out.println(i); } } 
지금 테스트해보세요

산출:

출력은 다음과 같습니다.

postgresql에서 열을 삭제하는 방법
 2017-05-01T20:57:32.709Z 

Java Instant now(시계시계) 방법 예

실시예 3

 import java.time.Clock; import java.time.Instant; public class InstantNowExample3 { public static void main(String[] args) { Instant instant = Instant.now(Clock.systemUTC()); System.out.println(instant); } } 
지금 테스트해보세요

산출:

출력은 다음과 같습니다.

 2017-03-15T09:18:34.062Z 

실시예 4

 import java.time.Clock; import java.time.Instant; import java.time.ZoneId; public class InstantNowExample4 { public static void main(String... args) { Instant i = Instant.now(Clock.system(ZoneId.of('America/Chicago'))); System.out.println(i); } } 
지금 테스트해보세요

산출:

출력은 다음과 같습니다.

 2017-05-01T20:57:34.818Z