|
한울 님이 쓰신 글 :
: VCL 라이브러리 중의 DeCodeDate(Days, soYear, soMonth, soDay); 함수를
:
: ISO C++ 표준에 맞는 함수로 바꾸려고 하는데요. 어떤 함수를 쓰면 가능할까요?
"time.h"에 선언된 time_t time(time_t *timer), struct tm *localtime(const time_t *timer) 함수가
ISO C++ 표준에 맞는 함수인지는 모르겠으나 아래와 같이 할 수는 있습니다.
TDateTime
The TDateTime class inherits a val data member declared as a double that holds the date-time value. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is the time of day.
time_t time(time_t *timer);
time gives the current time, in seconds, elapsed since 00:00:00 GMT, January 1, 1970, and stores that value in the location pointed to by timer, provided that timer is not a NULL pointer.
struct tm *localtime(const time_t *timer);
localtime accepts the address of a value returned by time and returns a pointer to the structure of type tm containing the time elements. It corrects for the time zone and possible daylight saving time.
struct tm *gmtime(const time_t *timer);
gmtime accepts the address of a value returned by time and returns a pointer to the structure of type tm containing the time elements. gmtime converts directly to GMT.
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
/************************************************************/
TDateTime 형의 입력을 struct tm 형으로 바꾸려면
TDateTime basetime(1970,1,1);
time_t timer = (time_t)((double)(Now()-basetime)*24*3600);
struct tm *tlocal = gmtime(&timer); // Now()가 local time을 반환하므로 localtime()이 아닌 gmtime()을 사용해야
printf("Local time is: %s", asctime(tlocal));
"time.h"에 있는 함수만 사용한다면 아래와 같이 합니다.
time_t curgmtime = time(NULL);
struct tm *tlocal = localtime(&curgmtime );
printf("Local time is: %s", asctime(tlocal));
/*
년 = tlocal->tm_year+1900
월 = tlocal->tm_mon+1
일 = tlocal->tm_mday
시 = tlocal->tm_hour
분 = tlocal->tm_min
초 = tlocal->tm_sec
요일 = tlocal->tm_wday (일요일=0 ~ 토요일=6)
*/
|