linux-kernel - Linux内核中的人类可读时间戳

标签 linux-kernel kernel kernel-module

如何在Linux内核中编写人类可读的时间戳?我认为do_gettimeofday返回纪元,但我不想尝试将其转换为可读时间。我只想要Hour:Min:Sec:Msec这样的格式。
谢谢

最佳答案

后来的内核具有time_to_tm函数,可以将时间间隔转换为人类可读的格式。

这是一个例子:

struct timeval t;
struct tm broken;
do_gettimeofday(&t);
time_to_tm(t.tv_sec, 0, &broken);
printk("%d:%d:%d:%ld\n", broken.tm_hour, broken.tm_min, 
                         broken.tm_sec, t.tv_usec);

同样,这仅在更高版本的内核中可用。第二个参数time_to_tm是到纪元时间的偏移量。在我本地时间是0,我不知道您应该使用哪一个。

关于linux-kernel - Linux内核中的人类可读时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8653839/

相关文章:

android - 在金鱼内核中添加类似的头文件

gcc - 使用带有内核头文件的 gcc 编译 Linux 内核模块

c - 如何给Linux系统调用传递参数?

linux - struct sched_pa​​ram 中的 sched_priority 指的是什么?

c - 在 Linux 内核中使用模块覆盖功能

c - 如何将宏调用函数转换为内核函数?

javascript - 如何从 Linux shell 执行 javascript 程序?

memory-management - x86 的物理内存地址到 DRAM 映射信息

linux - 自定义 Linux 内核的 ioctl 突然停止响应并在几分钟后重新启动

c - `#ifdef MODULE` 围绕 module_exit() 的用途?