Home › C Tutorial › C date and time
C date and time
time.h basics.
time(NULL) returns seconds since 1970. localtime and strftime format it.
Example code
#include <stdio.h>
#include <time.h>
int main() {
time_t now = time(NULL);
char b[40];
strftime(b, 40, "%Y-%m-%d", localtime(&now));
printf("%s\n", b);
return 0;
}