c语言中获取当前时间的代码,求解释!!

发布网友

我来回答

1个回答

热心网友

(1)

time_t time ( time_t * timer );

The function returns this value, and if the argument is not a null pointer,
the value is also set to the object pointed by timer.

(2)

struct tm * localtime ( const time_t * timer );

Uses the time pointed by timer to fill a tm
structure with the values that represent the corresponding local time.

(3)

struct tm {
        int tm_sec;     /* seconds after the minute - [0,59] */
        int tm_min;     /* minutes after the hour - [0,59] */
        int tm_hour;    /* hours since midnight - [0,23] */
        int tm_mday;    /* day of the month - [1,31] */
        int tm_mon;     /* months since January - [0,11] */
        int tm_year;    /* years since 1900 */
        int tm_wday;    /* days since Sunday - [0,6] */
        int tm_yday;    /* days since January 1 - [0,365] */
        int tm_isdst;   /* daylight savings time flag */
        };

( 4 )

int atoi(  const char *str );

Convert a string to integer.

 

你代码中的if语句就是拿当前时间records中第i个时间比较,如果当前时间的小时不大于records[i]的小时,且分钟小于records[i]中的分钟,则返回1(应该是没超出),否则返回0(超出)。

懂了吗,宝贝?

追问其实你的中文回答我还看得懂。我看不懂的是
struct tm *local; //时间结构体
time_t t; //把当前时间给t
t=time(NULL); //NULL在stdio.h中定义为0,机器时间
local=localtime(&t); //获取当前系统时间

就这几句,麻烦详细解说一下。

追答struct tm *local; //时间结构体 

time_t t;

time_t被定义为位的整形

t=time(NULL);

     

该函数返回从1970年到执行该函数哪那一刻时间的秒数,将这个秒数赋值给t

local=localtime(&t);

 //将1970到运行时的秒数转化为年月日时分秒,年从1900年到现在的年数,应该为115,也可以手动转换,不调用这个函数

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com