다음을 통해 공유


localtime, _localtime32, _localtime64

시간 값을 변환하고 표준 시간대를 수정합니다. 이러한 기능의 더 안전한 버전을 사용할 수 있습니다. localtime_s, _localtime32_s, _localtime64_s를 참조하십시오.

struct tm *localtime(
   const time_t *timer 
);
struct tm *_localtime32(
   const __time32_t *timer
);
struct tm *_localtime64(
   const __time64_t *timer 
);

매개 변수

  • timer
    저장 된 시간에 대한 포인터입니다.

반환 값

구조 결과에 대한 포인터를 반환하거나 또는 NULL 함수에 전달 된 날짜입니다.

  • Before midnight, January 1, 1970.

  • After 03:14:07, January 19, 2038, UTC (_time32 및 time32_t 사용).

  • After 23:59:59, December 31, 3000, UTC (_time64 및 __time64_t사용).

_localtime32 가 03:14:07 January 19, 2038, UTC 까지 표현하는 반면에 __time64_t 를 사용하는_localtime64 는 세계 협정시(UTC) 23:59:59, December 31, 3000 까지 데이터를 표현하도록 합니다.

localtime는 _localtime64로 계산되는 인라인 함수이고 time_t은 __time64_t과 동일합니다. 컴파일러가 time_t 를 예전 32 비트 time_t 로서 번역하도록 할 필요가 있을 때에는 _USE_32BIT_TIME_T 를 정의할 수 있습니다. 이것을 하는 것은 _localtime32를 계산하기 위해 localtime를 호출합니다. 2038년 1월 1일 이후 응용 프로그램이 실패할 수 있고 64비트 플랫폼에서 허용되지 않기 때문에 이것은 권장되지 않습니다.

tm형식의 구조체의 필드는 각각이 int인 다음 값들을 저장합니다.

  • tm_sec
    Seconds after minute (0 – 59).

  • tm_min
    Minutes after hour (0 – 59).

  • tm_hour
    자정 이후 시간(0-23)입니다.

  • tm_mday
    Day of month (1 – 31).

  • tm_mon
    Month (0 – 11; January = 0).

  • tm_year
    Year (current year minus 1900).

  • tm_wday
    Day of week (0 – 6; Sunday = 0).

  • tm_yday
    Day of year (0 – 365; January 1 = 0).

  • tm_isdst
    일광 절약 시간(서머타임)이 적용중이면, 양수 값입니다. 일광 절약 시간이 적용중이지 않으면 0입니다. 일광 절약 시간 상태를 알 수 없으면, 음수 값입니다. TZ 환경 변수가 설정됐을 경우, C 런타임 라이브러리는 일광 절약 시간(DST)의 계산을 구현하는 데에 있어서 미국의 규칙을 가정합니다.

설명

localtime 함수는 time_t 값으로 저장된 시간을 변환하고 결과를 tm 구조체에 저장합니다. long 값 timer는 협정 세계시 1970년 1월 1일 자정(00:00:00)이후부터 경과된 초 시간을 나타냅니다. 이 값은 보통 time함수에서 얻습니다.

gmtime, mktime, mkgmtime, 및 localtime 의 32Bit와 64Bit 버전은 모두 변환에 대해 스레드당 단일 tm 구조체를 사용합니다. 이러한 루틴 중 하나를 호출 할 때마다 이전 호출의 결과를 삭제합니다.

사용자가 처음 전역 환경 변수 TZ를 설정하면 localtime는 지역 시간 영역을 수정합니다. TZ가 설정되었을 때, 다른 세 가지 환경 변수들(_timezone, _daylight, _tzname) 역시 자동적으로 설정됩니다. TZ 변수가 설정되지 않은 경우, localtime는 제어판의 날짜/시간 응용 프로그램에서 지정된 표준 시간대 정보를 사용하려고 시도합니다. 이 정보를 얻을 수 없는 경우, PST8PDT(태평양 표준 시간대)가 기본적으로 사용됩니다. 이러한 변수 설명은 _tzset를 참조하십시오. TZ는 Microsoft 확장이며 localtime의 ANSI 표준 정의의 일부가 아닙니다.

참고

대상 환경은 일광 절약 시간 상태인지의 여부를 지정하려고 시도해야 합니다.

이러한 함수는 해당 함수 매개 변수의 유효성을 검사합니다. 만약 timer 가 null 포인터이거나 timer 값이 음수인 경우 이러한 함수는 매개 변수 유효성 검사 에 설명 된 것과 같이 잘못된 매개 변수 핸들러를 호출합니다. 실행을 계속할 수 있는 경우 함수는 NULL 값을 반환하고 errno 를 EINVAL로 설정합니다.

요구 사항

루틴

필수 헤더

localtime

<time.h>

_localtime32

<time.h>

_localtime64

<time.h>

호환성에 대한 자세한 내용은 소개 단원의 호환성 부분을 참조하십시오.

예제

// crt_localtime.cpp
// compile with: /W3
/* This program uses _time64 to get the current time 
 * and then uses localtime64() to convert this time to a structure 
 * representing the local time. The program converts the result 
 * from a 24-hour clock to a 12-hour clock and determines the 
 * proper extension (AM or PM).
 */

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

int main( void )
{
        struct tm *newtime;
        char am_pm[] = "AM";
        __time64_t long_time;

        _time64( &long_time );           // Get time as 64-bit integer.
                                         // Convert to local time.
        newtime = _localtime64( &long_time ); // C4996
        // Note: _localtime64 deprecated; consider _localetime64_s

        if( newtime->tm_hour > 12 )        // Set up extension.
                strcpy_s( am_pm, sizeof(am_pm), "PM" );
        if( newtime->tm_hour > 12 )        // Convert from 24-hour
                newtime->tm_hour -= 12;    //   to 12-hour clock.
        if( newtime->tm_hour == 0 )        // Set hour to 12 if midnight.
                newtime->tm_hour = 12;

        char buff[30];
        asctime_s( buff, sizeof(buff), newtime );
        printf( "%.19s %s\n", buff, am_pm );
}
  

해당 .NET Framework 항목

System::DateTime::ToLocalTime

참고 항목

참조

시간 관리

asctime, _wasctime

ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64

_ftime, _ftime32, _ftime64

gmtime, _gmtime32, _gmtime64

localtime_s, _localtime32_s, _localtime64_s

time, _time32, _time64

_tzset