This is how we can store the current time and print it using time.h
:
$ cat addt.c
#include<stdio.h>
#include<time.h>
void print_time(time_t tt) {
char buf[80];
struct tm* st = localtime(&tt);
strftime(buf, 80, "%c", st);
printf("%s\n", buf);
}
int main() {
time_t t = time(NULL);
print_time(t);
return 0;
}
$ gcc addt.c -o addt
$ ./addt
Sat Nov 6 15:55:58 2010
$
How can I add, for example 5 minutes 35 seconds to time_t t
and store it back in t
?