鍍金池/ 教程/ C/ mktime() - C語言庫函數
qsort() - C語言庫函數
strxfrm() - C語言庫函數
difftime() - C語言庫函數
isdigit() - C函數
<limits.h> - C語言標準庫
ldiv() - C語言庫函數
printf() - C語言庫函數
sin() - C函數
freopen() - C語言庫函數
NULL - C函數
mktime() - C語言庫函數
floor() - C函數
log() - C函數
rewind() - C語言庫函數
memcpy() - C語言庫函數
remove() - C語言庫函數
localtime() - C語言庫函數
strcoll() - C語言庫函數
fgets() - C語言庫函數
errno - C語言宏
<stdlib.h> - C語言標準庫
labs() - C語言庫函數
putchar() - C語言庫函數
wcstombs() - C語言庫函數
fclose() - C庫函數
system() - C語言庫函數
strncmp() - C語言庫函數
va_end() - C函數
setlocale() - C函數
strpbrk() - C語言庫函數
acos() - C函數
fabs() - C函數
asctime() - C語言庫函數
offsetof() - C函數
cos() - C函數
atoi() - C語言庫函數
strftime() - C語言庫函數
va_arg() - C函數
strstr() - C語言庫函數
<errno.h> - C語言標準庫
memchr() - C語言庫函數
fopen() - C語言庫函數
va_start() - C函數
fprintf() - C語言庫函數
strrchr() - C語言庫函數
<time.h> - C語言標準庫
C語言標準庫
isgraph() - C函數
srand() - C語言庫函數
isprint() - C函數
fputs() - C語言庫函數
sscanf() - C語言庫函數
getc() - C語言庫函數
<stdarg.h> - C語言標準庫
rename() - C語言庫函數
rand() - C語言庫函數
strspn() - C語言庫函數
frexp() - C函數
bsearch() - C語言庫函數
islower() - C函數
fwrite() - C語言庫函數
ispunct() - C函數
vsprintf() - C語言庫函數
strcspn() - C語言庫函數
fgetpos() - C庫函數
getchar() - C語言庫函數
tmpfile() - C語言庫函數
mbtowc() - C語言庫函數
sprintf() - C語言庫函數
ftell() - C語言庫函數
feof() - C庫函數
mblen() - C語言庫函數
clearerr() - C庫函數
modf() - C函數
strncat() - C語言庫函數
isspace() - C函數
ctime() - C語言庫函數
tmpnam() - C語言庫函數
isupper() - C函數
atol() - C語言庫函數
gets() - C語言庫函數
<setjmp.h> - C語言標準庫
perror() - C語言庫函數
exit() - C語言庫函數
memmove() - C語言庫函數
isalpha() - C函數
fsetpos() - C語言庫函數
fmod() - C函數
<float.h> - C語言標準庫
strtok() - C語言庫函數
wctomb() - C語言庫函數
strcat() - C語言庫函數
atof() - C語言庫函數
strchr() - C語言庫函數
<locale.h> - C語言標準庫
signal() - C函數
ungetc() - C語言庫函數
ferror() - C庫函數
C語言標準庫
strtoul() - C語言庫函數
fseek() - C語言庫函數
fscanf() - C語言庫函數
mbstowcs() - C語言庫函數
longjmp() - C函數
localeconv() - C函數
raise() - C函數
ceil() - C函數
<string.h> - C語言標準庫
free() - C語言庫函數
setvbuf() - C語言庫函數
atan() - C函數
C函數庫宏 assert()
<stdio.h> - C語言標準庫
fread() - C語言庫函數
vfprintf() - C語言庫函數
isxdigit() - C函數
toupper() - C函數
<ctype.h> - C語言標準庫
setjmp() - C函數
ldexp() - C函數
EDOM - C語言宏
strlen() - C語言庫函數
tolower() - C函數
clock() - C語言庫函數
fflush() - C庫函數
fgetc() - C語言庫函數
<stddef.h> - C語言標準庫
div() - C語言庫函數
<math.h> - C語言標準庫
isalnum() - C函數
memset() - C語言庫函數
calloc() - C語言庫函數
vprintf() - C語言庫函數
sqrt() - C函數
<assert.h> - C語言標準庫
time() C語言
atexit() - C語言庫函數
memcmp() - C語言庫函數
setbuf() - C語言庫函數
iscntrl() - C函數
abs() - C語言庫函數
abort() - C語言庫函數
exp() - C函數
realloc() - C語言庫函數
puts() - C語言庫函數
scanf() - C語言庫函數
malloc() - C語言庫函數
strerror() - C語言庫函數
strtol() - C語言庫函數
ERANGE - C語言宏
sinh() - C函數
atan2() - C函數
putc() - C語言庫函數
asin() - C函數
strcpy() - C語言庫函數
fputc() - C語言庫函數
getenv() - C語言庫函數
pow() - C函數
tanh() - C函數
gmtime() - C語言庫函數
strtod() - C語言庫函數
log10() - C函數
strcmp() - C語言庫函數
<signal.h> - C語言標準庫

mktime() - C語言庫函數

C庫函數 time_t mktime(struct tm *timeptr) 指向的結構轉換成一個time_t值,根據本地時區(qū)。

聲明

以下是mktime() 函數的聲明。

time_t mktime(struct tm *timeptr)

參數

  • timeptr -- 這是一個 time_t 值代表一個日歷時間分解成其組成部分的指針。下面是詳細的timeptr結構

struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */	
};

返回值

這個函數返回日歷時間作為參數傳遞一個time_t值對應的。錯誤時,返回-1值。

例子

下面的例子演示了如何使用mktime() 函數。

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

int main ()
{
   int ret;
   struct tm info;
   char buffer[80];

   info.tm_year = 2001 - 1900;
   info.tm_mon = 7 - 1;
   info.tm_mday = 4;
   info.tm_hour = 0;
   info.tm_min = 0;
   info.tm_sec = 1;
   info.tm_isdst = -1;

   ret = mktime(&info);
   if( ret == -1 )
   {
       printf("Error: unable to make time using mktime
");
   }
   else
   {
      strftime(buffer, sizeof(buffer), "%c", &info );
      print(buffer);
   }

   return(0);
}

讓我們編譯和運行上面的程序,這將產生以下結果:

Wed Jul 4 00:00:01 2001