에포크타임은 사람에겐 불편하지만 계산하기가 쉽다.
사람이 사용하는 날짜와 시간은 여러 진법이 섞여있어서 계산하기 어렵다.
https://standout.tistory.com/1246
epoch 에포크란?
epoch 에포크란? 보통 1970년 1월 1일 00:00:00 UTC가 기준, 이 시점부터 경과한 시간을 초로 표현. 에포크사용시 간단한 정규화된 시간표현을 제공하고 시간을 일관되게 관리할 수 있음. 유닉스 시간, P
standout.tistory.com
https://standout.tistory.com/1248#code_1704950259100
LocalDate와 LocalTime: get() getLong()특정필드값 가져오기, with() plus() minus() 변경하기, truncatedTo() 0으로
LocalDate와 LocalTime은 java.time 패키지의 가장 기본이 된다. 나머지 클래스들은 이들의 확장. https://standout.tistory.com/1245 java.time패키지: 객체생성 now() of() parse()와 인터페이스, 간격을 나타내는 Period Du
standout.tistory.com
Instant를 생성할때는 now()와 ofEpochSecond()를 사용한다.
now() 현재 시스템시간을 기반으로 Instant 생성
var currentInstant = java.time.Instant.now();
System.out.println("현재 Instant: " + currentInstant);
//현재 Instant: 2024-01-15T08:30:45.123456Z
ofEpochSecond() 1970년 1월 1일 부터 지정된 초만큼 지난 시간의 Instant를 생성한다.
var epochSecond = 1609459200; // 2023년 1월 1일 00:00:00 (UTC)의 초
var instantFromEpochSecond = java.time.Instant.ofEpochSecond(epochSecond);
System.out.println("지정된 초 이후의 Instant: " + instantFromEpochSecond);
//지정된 초 이후의 Instant: 2023-01-01T00:00:00Z
밀리초단위의 epochtime을 필요로 한다면 toEpochMilli()를 사용한다.
var currentInstant = java.time.Instant.now();
var epochMillis = currentInstant.toEpochMilli();
System.out.println("현재 Instant의 Epoch Millis: " + epochMillis);
//현재 Instant의 Epoch Millis: 1642266645123
Instant는 기존의 java.util.Date를 대체하기 위해나왔다.
Date는 Instant로, Instant는 Date로 변환할 수 있다.
import java.time.Instant;
import java.util.Date;
var currentInstant = Instant.now();
var dateFromInstant = Date.from(currentInstant);
System.out.println("Instant에서 변환된 Date: " + dateFromInstant);
//Instant에서 변환된 Date: Fri Jan 13 10:35:45 UTC 2023
import java.time.Instant;
import java.util.Date;
var currentDate = new Date();
var instantFromDate = currentDate.toInstant();
System.out.println("Date에서 변환된 Instant: " + instantFromDate);
//Date에서 변환된 Instant: 2023-01-13T10:35:45.123456Z