如何在 Minix 3.2.1 的 printf
中写入当前时间?
我尝试像下面那样使用 gmtime
但它在 time(&nowtime)
上出错。
#include <sys/time.h>
#include <time.h>
struct tm *now;
time_t nowtime;
time(&nowtime);
now=gmtime(&nowtime);
printf("TIME is NOW %s",now);
此外,我试图在内核 (/usr/src/kernel/main.c) 中记忆起它,因为我需要在启动 minix 时告知内核进程何时完成并切换到用户。
我在上面的代码中遇到了一些错误,比如在像下面这样重建内核时;
最佳答案
不太熟悉 minix,但它类似于 Unix 和 Linux,所以可能来自该平台的某些东西可能出现在 minix 上......所以有几种方法
在
ctime
上运行 manLinux 的
time()
命令的手册页包含此示例代码(您可能需要为 minix 修改它,但它显示了如何使用asctime()
localtime()
和time()
):#include <stdio.h> #include <time.h> int main(void) { time_t result; result = time(NULL); printf("%s%ju secs since the Epoch\n", asctime(localtime(&result)), (uintmax_t)result); return(0); }
关于c - 当前时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26951000/