지정 한 날 짜 를 초 로 변환 합 니 다.

1735 단어
헤더 파일:
필요 한 데이터 형식: timet,struct tm
필요 함수: timet mktime(struct tm * timeptr);
대상: 지 정 된 날 짜 를 1970.1.1 에서 지나 간 초 로 변환 합 니 다.
과정: tm 데이터 구 조 를 작성 하고 함수 에 전송 하여 time 를 되 돌려 줍 니 다.t 의 결과.
다음은 msdn 이 mktime 함수 에 대한 설명 입 니 다.
 
time_t mktime(
   struct tm *timeptr 
);
__time32_t _mktime32(
   struct tm *timeptr 
);
__time64_t _mktime64(
   struct tm *timeptr 
);

 
_mktime32 returns the specified calendar time encoded as a value of type time_t. If timeptr references a date before midnight, January 1, 1970, or if the calendar time cannot be represented, _mktime32 returns –1 cast to type time_t. When using _mktime32 and if timeptr references a date after 03:14:07 January 19, 2038, Coordinated Universal Time (UTC), it will return –1 cast to type time_t.
_mktime64 will return –1 cast to type __time64_t if timeptr references a date after 23:59:59, December 31, 3000, UTC.
 
다음은 실례 입 니 다.
#include
#include
 
int main( void ){
struct tm when;
__time64_t now, result; int days;
 char buff[80]; time( &now );
_localtime64_s( &when, &now );
asctime_s( buff, sizeof(buff), &when );
 printf( "Current time is %s", buff );
days = 20;
when.tm_mday = when.tm_mday + days;
 if( (result = mktime( &when )) != (time_t)-1 ) {
       asctime_s( buff, sizeof(buff), &when );
      printf( "In %d days the time will be %s", days, buff );
    } else perror( "mktime failed" );
}

좋은 웹페이지 즐겨찾기