如何在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/