2010-08-17 72 views

回答

18

strftime

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

int main() 
{ 
    char date[9]; 
    time_t t = time(0); 
    struct tm *tm; 

    tm = gmtime(&t); 
    strftime(date, sizeof(date), "%Y%m%d", tm); 
    printf("log.%s\n", date); 
    return EXIT_SUCCESS; 
} 
+0

你实际上不需要'tm'临时文件 - 你可以直接将'gmtime(&t)'的返回值传递给'strftime()'。 – caf 2010-08-18 02:18:24

+0

@caf:我认为重点是要显示'gmtime'返回的内容。通常你不会只打印它。 – bitmask 2013-07-30 16:20:50