【发布时间】:2014-11-15 21:36:54
【问题描述】:
如何在 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 启动时说明内核进程何时完成并切换到用户。
我在上面的代码中出现了一些错误,比如像下面这样重建内核时;
【问题讨论】:
-
1) 代码中是否包含
<time.h>? 2) 发布错误信息。 -
是的 time.h 包含在 struct tm *now 中,使用不同的类型重新定义“now”的错误。我现在也用 nowwwww 进行更改,但仍然给出相同的错误
-
似乎存在矛盾:“在
time(&nowtime)上给出错误”和“struct tm *now给出'现在'的错误重新定义”。time(&nowtime)上的可疑错误是not。 -
将其扩展为一个完整的可编译程序(它应该只需要多几行),然后将确切的错误消息复制并粘贴到您的问题中。
标签: c unix unix-timestamp minix