본문으로 바로가기
반응형

ISO 8601은 날짜와 시간 정보를 표준화된 형식으로 표현하기 위한 국제 표준이다.

 

ISO 8601의 기본 형식

YYYY-MM-DDTHH:MM:SSZ

 

예를 들어 2025-06-09T12:05:13Z 이런 식으로 출력이 되게 된다.

 

YYYY 연도 2025
MM 월 (01~12) 06
DD 일 (01~31) 09
T 날짜와 시간 사이 구분 문자 -
HH 시 (00~23) 14
MM 분 (00~59) 33
SS 초 (00~59) 00
Z 또는 +09:00 시간대(UTC/Z=UTC 기준 / +오프셋) Z 또는 +09:00

 

예제코드

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <time.h>

int main(void)
{
    time_t now = time(NULL);
    struct tm* utc_time, * kst_time;
    char timestamp[30];
    
    utc_time = gmtime(&now);                                                        // UTC 시간으로 변환
    memset(timestamp, 0x00, sizeof(timestamp));
    strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%SZ", utc_time);         // ISO 8601 형식으로 포맷팅

    printf("UTC timestamp: %s\n", timestamp);

   // 한국 시간
    now += 9 * 60 * 60;                                                             // 9시간 = 9 * 3600 = 32400초
    kst_time = gmtime(&now); // 이제 UTC 기준으로 +9된 시간
    memset(timestamp, 0x00, sizeof(timestamp));
    strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S+09:00", kst_time);    // ISO 8601 형식 + 시간대 표기

    printf("KST timestamp: %s\n", timestamp);

	return 0;
}

 

출력

UTC timestamp: 2025-06-09T12:03:06Z
KST timestamp: 2025-06-09T21:03:06+09:00

 

은근히 써먹을 곳이 많은 UTC

 

반응형