C语言中获得本地日期

代码如下:

#include 
#include 


int main(int argc, char** argv)
{
    struct tm *date;
    time_t t;

    t=time(NULL);
    date=localtime(&t);
    printf("Local time is: %d:%d:%d\n", date->tm_hour, date->tm_min, date->tm_sec);

    date=gmtime(&t);
    printf("UTC time is: %d:%d:%d\n",   date->tm_hour, date->tm_min, date->tm_sec);

    return 0;
}

 

你可能感兴趣的:(C/C++)