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

前端 未结 5 696
我在风中等你
我在风中等你 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 08:57

    Converting the do_gettimeofday result to an hour is pretty simple, since it starts at midnight GMT.

    time_t t = time(0);
    time_t SecondsOfDay = t % (24*60*60);
    time_t HourGMT = SecondsOfDay / (60*60);
    

    Then adjust for your local timezone

提交回复
热议问题