본문 바로가기

Programming

Linux C - 현재시간

+ 현재 시간 출력
=======================================================================================
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(void){
        char time_string[40];
        struct timeval now;
        struct tm* ptm;
        gettimeofday(&now, (struct timezone *) NULL);
        ptm = localtime(&now.tv_sec);
        strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm);
        printf("%s\n", time_string);
        return 0;
}
=======================================================================================