【发布时间】:2011-05-06 01:25:09
【问题描述】:
这就是我们如何存储当前时间并使用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
$
如何将例如 5 分 35 秒添加到 time_t t 并将其存储回 t?
【问题讨论】:
-
看看stackoverflow.com/questions/1859201/add-seconds-to-a-date>
-
(严格来说它不是重复的,但考虑到实际提供的答案,它是另一个问题的子集)。