获取当前小时下使用time.h中 [英] Getting the current hour in C using time.h

查看:326
本文介绍了获取当前小时下使用time.h中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总新手的问题在这里;我提前道歉。

Total newbie question here; I apologize in advance.

假如我有C语言编写的一个守护进程,唤醒自身每隔五分钟左右,做了一些处理,如果有在其输入队列什么,然后就回去睡觉。现在假设有一些处理,它仅具有一定的(可配置)的时间后做 - 比如,下午2点(午夜前)

Suppose I have a daemon written in C that wakes itself up every five minutes or so, does some processing if there's anything in its input queue, and then goes back to sleep. Now suppose there is some processing that it only has to do after a certain (configurable) time--say, 2 pm (and before midnight).

在C,什么是获取当前时间的小时到一个int变量,因此,它可以很容易地核对最快,最好的方式 - 来确定的话,其实,这是在14:00以后今天

In C, what is the quickest, best way to get the current time's hour into an int variable, so that it can easily be checked against--to determine if, in fact, it is after 2pm on today?

推荐答案

本地时间。请参见 http://linux.die.net/man/3/localtime

struct tm *tm_struct = localtime(time(NULL));

int hour = tm_struct->tm_hour;

这篇关于获取当前小时下使用time.h中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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