How to get current hour (time of day) in linux kernel space

前端 未结 5 703
我在风中等你
我在风中等你 2020-12-14 08:14

I\'m writing a kernel module that checks to see if the time is between two specified hours, and disables input if it is. This has to do with me wanting to make sure I go to

5条回答
  •  攒了一身酷
    2020-12-14 09:06

    To get the local time in kernel, add the below code snippet your kernel driver:

    struct timeval time;
    unsigned long local_time;
    
    do_gettimeofday(&time);
    local_time = (u32)(time.tv_sec - (sys_tz.tz_minuteswest * 60));
    rtc_time_to_tm(local_time, &tm);
    
    printk(" @ (%04d-%02d-%02d %02d:%02d:%02d)\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
    

提交回复
热议问题