Heesung Yang

C - How to handle time (time_t)

How to handle time in C language (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;
}

Next post

Bash Color