10-5. UTC

박은서's avatar
Feb 06, 2026
10-5. UTC

1. UTC(세계표준협정시, Coordinated Universal Time)

1️⃣ UTC 란?

전 세계에서 공통으로 사용하는 기준 시간
  • 영국(그리니치) 기준 시간과 거의 동일
  • 서머타임, 국가별 시간 변화와 무관
  • “지금이 언제인가”를 하나의 기준으로 표현하기 위한 시간
핵심 : UTC는 “지역 시간”이 아니라 “기준 시간”

2️⃣ 1970-01-01과 초 단위 시간 (Unix Time)

1) 컴퓨터 세계에서 시간

컴퓨터 세계에서는 시간을 이렇게 표현하는 경우가 많음
1970년 1월 1일 00:00:00 (UTC)부터 경과한 초
이를 보통:
  • Unix Time
  • Epoch Time
    • 라고 부른다.

2) 예시

  • 0 → 1970-01-01 00:00:00 UTC
  • 1 → 1초 뒤
  • 60 → 1분 뒤
📌 중요한 점
  • 이 값은 타임존 개념이 없다
  • 그냥 “초의 개수”일 뿐

3️⃣ 타임존(Time Zone)이 왜 중요한가

사람이 보는 시간은 항상 타임존이 필요하다.

예시

  • 한국 : UTC +9
  • 일본 : UTC +9
  • 미국 뉴욕 : UTC -5 (서머타임 시 -4)
같은 UTC 시간이라도:
  • UTC 00:00
  • 한국 → 09:00
  • 뉴욕 → 전날 19:00
➡️ 시간 값 + 타임존 = 사람이 이해하는 시간

4️⃣ 한국 서비스 vs 글로벌 서비스

1) 한국에서만 쓰는 서비스

  • 서버, DB, 사용자 모두 한국
  • 전부 KST(UTC+9) 기준으로 처리해도 큰 문제 없음
예:
  • 2026-02-05 10:00
  • 그냥 “한국 시간”으로 해석
⚠️ 단점
  • 나중에 글로벌 확장 시 전부 수정해야 할 수 있음

2) 글로벌 서비스

반드시 UTC 기준으로 저장해야 함
권장 패턴
  1. 저장
      • 모든 시간은 UTC로 저장
  1. 계산
      • 서버 로직도 UTC 기준
  1. 표시
      • 사용자에게 보여줄 때만 타임존 변환
  • DB 저장: 2026-02-05T01:00:00Z (UTC)
  • 한국 사용자 표시: 2026-02-05 10:00
  • 미국 사용자 표시: 2026-02-04 20:00

5️⃣ 타임존은 어디에 속해야 할까?

1) ❌ OS 타임존에 의존

  • 서버 OS 시간 변경
  • 컨테이너 / 클라우드 환경
  • 국가별 서버 혼합
예측 불가, 버그 발생 가능

2) ✅ 애플리케이션이 타임존을 명확히 관리

베스트 프랙티스
  • 서버 내부 로직: UTC 고정
  • DB: UTC
  • 애플리케이션 설정: 명시적 타임존
  • 사용자 프로필: 사용자 타임존 저장
타임존은 “환경”이 아니라 “데이터”로 다뤄야 한다

6️⃣ 필기

notion image
notion image

7️⃣ 실습

1) 여러가지 날짜 함수

C:\workspace\spring_lab\skillapp\src\main\java\ex03\TimeEx01.java
package ex03; import java.sql.Timestamp; import java.time.*; public class TimeEx01 { public static void main(String[] args) { // 1. 로컬 데이트 타임 LocalDateTime now1 = LocalDateTime.now(); // 자바 레벨의 타임존 System.out.println("LocalDateTime : " + now1); // 2. 존을 설정해서 시간 만들기 (X) ZonedDateTime now2 = ZonedDateTime.now(ZoneOffset.UTC); System.out.println("ZonedDateTime : " + now2); // 3. Instant 시간 (O) Instant now3 = Instant.now(); System.out.println("Instant : " + now3); // 4. Timestamp (milliseconds - 1/1000초) 내부적으로 컴버팅해줌 // 시간이 변환되서 출력됨(위험) -> 안쓰는 것이 좋음 Timestamp now4 = new Timestamp(1000 * 300); System.out.println("Timestamp(1) : " + now4); Timestamp now5 = new Timestamp(System.currentTimeMillis()); System.out.println(System.currentTimeMillis()); System.out.println("Timestamp(2) : " + now5); } }
notion image

2) LocalDateTime

날짜 관련 함수 매우 많이 들고 있음
한국에서만 쓸거면 이것만 써도 됨!
C:\workspace\spring_lab\skillapp\src\main\java\ex03\TimeEx02.java
package ex03; import java.time.LocalDateTime; public class TimeEx02 { public static void main(String[] args) { // 1. 로컬 데이트 타임 (벽시계 - 문자열로 박힌 시계) LocalDateTime now1 = LocalDateTime.now(); // 현재 시간 System.out.println("now : " + now1); System.out.println("=============================================="); // 년, 월, 일, 시, 분, 초 System.out.println("년 : " + now1.getYear()); System.out.println("월 : " + now1.getMonth()); System.out.println("일 : " + now1.getDayOfMonth()); System.out.println("시 : " + now1.getHour()); System.out.println("분 : " + now1.getMinute()); System.out.println("초 : " + now1.getSecond()); System.out.println("=============================================="); // 날짜 더하기, 시간 더하기 System.out.println("now + 5년 : " + now1.plusYears(5)); System.out.println("now + 5개월 : " + now1.plusMonths(5)); System.out.println("now + 5일 : " + now1.plusDays(5)); System.out.println("now + 5시간 : " + now1.plusHours(5)); System.out.println("now + 5분 : " + now1.plusMinutes(5)); System.out.println("now + 5초 : " + now1.plusSeconds(5)); System.out.println("=============================================="); // 2026-01-30T15:43:11.740733800 // 2026-01-30T06:43:11.740733800Z (Z 붙어있으면 UTC(초)로 저장되어 있음) } }
notion image
Share article