<aside> 💡

쿠폰 만료시간 2026.01.30

내가 한국에 있으면?

내가 미국에 있으면?

1) 쿠폰이 만료되는 ‘정책(접속 나라가 되면 당연히 안되겠지?)’을 명확히 정의하고

2) 결제/검증은 항상 ‘절대시각(Instant, UTC)’으로 처리한다

</aside>

심플 정리

package ex03;

import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

public class TimeEx01 {
    public static void main(String[] args) {
        // 1. 로컬 데이트 타임 (UTC로 세팅되있음)
        LocalDateTime now1 = LocalDateTime.now();
        System.out.println(now1);

        // 2. 존을 설정해서 시간 만들기 (X)
        ZonedDateTime now2 = ZonedDateTime.now(ZoneOffset.UTC);
        System.out.println(now2);

        // 3. Instant 시간 (O)
        Instant now3 = Instant.now();
        System.out.println(now3);

        // 4. Timestamp (1/1000) -> 시간이 변환되서 출력됨!! (x)
        Timestamp now4 = new Timestamp(1000 * 60 * 60 * 10);
        System.out.println(now4);

        Timestamp now5 = new Timestamp(System.currentTimeMillis()+1000 * 60 * 60 * 10);
        System.out.println(System.currentTimeMillis());
        System.out.println(now5);
    }
}

package ex03;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class TimeEx02 {
    public static void main(String[] args) {
        // 1. 로컬 데이트 타임 (벽시계 - 문자열로 박힌 시계)
        LocalDateTime now1 = LocalDateTime.now();

        // 년 월 일
        System.out.println("Year : " + now1.getYear());
        System.out.println("Month : " + now1.getMonth());
        System.out.println("DayOfMonth : " + now1.getDayOfMonth());
        System.out.println("DayOfWeek : " + now1.getDayOfWeek());
        System.out.println("DayOfYear : " + now1.getDayOfYear());

        System.out.println("=======================");

        System.out.println("Hour : " + now1.getHour());
        System.out.println("Min : " + now1.getMinute());
        System.out.println("Second : " + now1.getSecond());

        System.out.println("=======================");

        System.out.println(now1.plusDays(2));
        System.out.println(now1.plusHours(9));

        //2026-01-30T15:43:11.740733800
        //2026-01-30T06:43:11.740733800Z

    }
}

자바 시간 vs DB 시간 완전 정리

🔥 핵심 메시지

“자바 시간은 ‘기계 시간’과 ‘사람 시간’이 섞여 있고 DB 시간은 ‘날짜 타입’이지 ‘에포크 초’가 아니다.”

1️⃣ 시간 개념 3단계 모델 (이거부터 고정)

[절대 시간]     →[시간대 적용]       →[표현용 벽시계]
Instant         ZonedDateTime       LocalDateTime
(UTC 기준)      (UTC + TZ)          (시간대 없음)

2️⃣ 자바 시간 타입 정리

✅ ① Instant (표준, 정답)

Instantnow= Instant.now();

📌 특징

java.sql.Timestamp (이름이 사고 유발)