블로그는 나의 힘!
[ Programing ]/C++2010. 1. 31. 07:01
#include <stdio.h>
#include <time.h>

time_t tTimer;
tm* _sTM;

tTimer = time( NULL );            // 현재 시간을 초 단위로 가져옴
_sTM = localtime( &tTimer );   // 초 단위의 시간을 분리해 구조체에 입력


printf( "Time : %d second \n\n", tTimer );                   // 1970/01/01/00:00:00 ~ 현재 ( Unix 시간 )

printf( "Year: %d \n",   _sTM->tm_year + 1900 );           // 년
printf( "Month: %d \n",   _sTM->tm_mon + 1 );             // 월
printf( "Day: %d \n\n", _sTM->tm_mday );                 // 일

printf( "Hour: %d \n",   _sTM->tm_hour );                    // 시
printf( "Minute : %d \n",   _sTM->tm_min );                 // 분
printf( "Second : %d \n\n", _sTM->tm_sec );             // 초

printf( "Week : %d \n", _sTM->tm_wday );                  // 일 : 0, 월 : 1, 화 : 2, 수 : 3, 목 : 4, 금 : 5, 토 : 6
printf( "Year is Day: %d \n", _sTM->tm_yday );           // 0 ~ 365일 ( 올해의 몇번째의 날짜 인지 출력 )
printf( "Summer time : %d \n\n", _sTM->tm_isdst );    //  Summer time 아님 : 0 ( 일광 시간 )




- 시간 / 날짜 출력
- time()으로 현재 시간을 구한 후 localtime()으로 tm구조체에 저장.
- tm 구조체는 아래 참조

struct tm 
{
    int tm_sec;       /* seconds after the minute - [0,59] */   // 0 ~ 59 초
    int tm_min;       /* minutes after the hour - [0,59] */        // 0 ~ 59 분
    int tm_hour;      /* hours since midnight - [0,23] */        // 0 ~ 23 시
    int tm_mday;    /* day of the month - [1,31] */               // 1 ~ 31 일
    int tm_mon;      /* months since January - [0,11] */       // 0 ~ 11 월
    int tm_year;      /* years since 1900  */                         // 년( 1900년 부터 기준이다. )
    int tm_wday;    /* days since Sunday - [0,6] */            // 0 ~ 6 요일
    int tm_yday;     /* days since January 1 - [0,365] */      // 0 ~ 365 일
    int tm_isdst;     /* daylight savings time flag */              // 일광 시간 ( Summer Time )
};




'[ Programing ] > C++' 카테고리의 다른 글

[ 기초 ] 팁 : 조건문 효율적으로 붙이기  (0) 2010.01.31
[심심풀이] VECTOR 만들기  (0) 2010.01.31
가변인자  (0) 2010.01.30
Console 환경 전용 API 함수  (0) 2010.01.29
Visual C++ Console에서 TurboC gotoxy구현  (0) 2010.01.29
Posted by Mister_Q