c - 当前时间

标签 c unix unix-timestamp minix

如何在 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 时告知内核进程何时完成并切换到用户。

我在上面的代码中遇到了一些错误,比如在像下面这样重建内核时;

enter image description here

最佳答案

不太熟悉 minix,但它类似于 Unix 和 Linux,所以可能来自该平台的某些东西可能出现在 minix 上......所以有几种方法

  • ctime 上运行 man

  • Linux 的 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/

相关文章:

Bash - 从字符串中提取数字

c# - 将纪元/unix 转换为日期时间

Mysql 选择日期时间,大于时间戳

c - 为什么在创建结构时需要地址运算符(&)?

c++ - 以二进制和文本模式写入的文件之间的区别

c - 这个无名变量是什么? C

c - 如何检查是否为条件编译定义了枚举项?

Shell 脚本 - 检查语法

windows - 使用 Powershell 的 UNIX 格式文件

php - 如何使用 CURRENT_TIMESTAMP 在 mysql 中将 Gregorian 格式转换为 Solar 格式