Heesung Yang

C - 시간 다루기

C 언어에서 시간 다루기 (time_t)

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

int main() {

    char buf[20];

    # get current time
    time_t now = time(NULL);

    # print as number (epoch time)
    printf("%ld\n", now);         // 1632404344

    strftime(buf, 20, "%Y-%m-%d", localtime(&now));
    printf("%s\n", buf);          // 2021-09-23

    return 0;
}