Linux内核中的人类可读时间戳 [英] human readable timestamp in linux kernel

查看:269
本文介绍了Linux内核中的人类可读时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I write human readable timestamp in linux kernel? I think do_gettimeofday returns epoch but I don't want to try to convert it to readable time. I just want a format like Hour:Min:Sec:Msec. Thanks

推荐答案

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

Later kernels have a function time_to_tm to break epoch time into human readable format.

这是一个例子:

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,我不知道您应该使用哪一个.

Again, this is only available in later kernels. The second parameter time_to_tm is an offset to the epoch time. In my local time is 0, I don't know which one you should use.

这篇关于Linux内核中的人类可读时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆