[Java] TimeStamp, LocalDateTime, Instant 비ꡐ

μžλ°”μ—μ„œ μ‚¬μš©ν•˜λŠ” TimeStamp, Unix TimeStamp, LocalDateTime, Instant λŠ” 무엇인지 μ•Œμ•„ λ³΄κ² μŠ΅λ‹ˆλ‹€.

μœ λ‹‰μŠ€ νƒ€μž„μŠ€νƒ¬ν”„(Unix TimeStamp)

μœ λ‹‰μŠ€ νƒ€μž„μŠ€νƒ¬ν”„ -> LocalDateTime λ³€ν™˜

μ•„λž˜ μ˜ˆμ œλŠ” Import 토큰을 νšλ“ APIλ₯Ό μš”μ²­ν•˜κ³ , 응닡받은 JSONμž…λ‹ˆλ‹€. λ§Œλ£Œμ‹œκ°„μ΄ μœ λ‹‰μŠ€ νƒ€μž„ μŠ€νƒ¬ν”„μ΄κΈ° λ•Œλ¬Έμ— LocalDateTime으둜 λ³€ν™˜μ‹œμΌœμ•Ό ν•©λ‹ˆλ‹€.

{
  "code": 0,
  "message": null,
  "response": {
    "access_token": "a9ace025c90c0da2161075da6ddd3492a2fca776",
    "now": 1512446940,
    "expired_at": 1512448740
  }
}
long expiredAt = 1512448740;
LocalDateTime result = LocalDateTime.ofInstant(Instant.ofEpochSecond(expiredAt), TimeZone.getDefualt().toZoneId());

System.out.println(result); //2017-12-05T13:39

LocalDateTime vs Instant 비ꡐ

LocalDateTime

Instant

LocalDateTime now = LocalDateTime.now();
Instant instantNow = Instant.now();

System.out.println(now);  //2019-08-01T16:41:28.027
System.out.println(instantNow); //2019-08-01T07:41:28.027Z

2번째 Instant κ°μ²΄λŠ” 뒀에 Zκ°€ λΆ™μ–΄μžˆλŠ” 것을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ—°κ΄€ 포슀트