app制作网站有哪些 请列举网站如何优化关键词排名
C语言时间日期函数总结
C语言时间日期函数总结C语言时间日期函数总结用到的数据结构:time_t是一个long类型 代表机器时间,可由time( )函数获得。
日历时间用一个(char *) 类型的字符串表示。格式为:星期 月 日 小时:分:秒 年\n\0可由函数ctime( ) asctime( ) 得到。
以tm结构表达的时间,结构tm定义如下: struct tm { 可由函数localtime( ), gmtime( )得到 int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }; //系统日期 struct date { int da_year; /* Year - 1980 */ char da_day; /* Day of the month */ char da_mon; /* Month (1 = Jan) */ };//系统时间struct time { unsigned char ti_min; /* Minutes */ unsigned char ti_hour; /* Hours */ unsigned char ti_hund; /* Hundredths of seconds */ unsigned char ti_sec; /* Seconds */ };
用到的函数:char * asctime(struct tm * ptr) 将tm结构的时间转化为日历时间。char *ctime(long time) 将机器时间转化为日历时间。struct tm *gmtime(time_t *time) 将机器时间转化为tm时间
当ptr为空时,得到机器时间;非空时,设置机器时间。time_t time(time_t *ptr) 得到或设置机器时间double difftime(time_t time2, time_t time1) 得到两次机器时间差,单位为秒
long dostounix(struct data *d, struct time *t) 将DOS的日期和时间格式转换成UNIX标准(机器时间(用到dos.h库).void unixtodos(long utime, struct date *d, struct time *t) 将UNIX格式的时间和日期转换成DOS格式(由time 和date两部分组成,只能由机器时间得到,并且用到dos.h库)void getdate(struct date *d) 得到系统日期,d 存放得到的日期信息void setdate(struct date *d)void gettime(struct date *t) 得到系统时间 d 存放得到的时间信息void settime(struct date *t)