C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[58141] Re:VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요..
Z [] 1324 읽음    2009-08-23 12:51
한울 님이 쓰신 글 :
: 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)
*/

+ -

관련 글 리스트
58138 VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요.. 한울 883 2009/08/23
58150     Re:VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요.. 김상구.패패루 1076 2009/08/24
58141     Re:VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요.. Z 1324 2009/08/23
58147         Re:Re:VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요.. 한울 889 2009/08/24
58149             Re:Re:Re:VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요.. Z 928 2009/08/24
58179                 VCL의 DeCodeDate() 함수를 표준 C++ 함수로바꾸려고 하는데요.. 한울 1187 2009/08/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.