- /* *******************************
- * from linux 0.11
- *
- * file: linux/include/time.h
- *********************************/
- #ifndef _TIME_H
- #define _TIME_H
- #ifndef _TIME_T
- #define _TIME_T
- typedef long time_t;
- #endif
- #ifndef _SIZE_T
- #define _SIZE_T
- typedef unsigned int size_t
- #endif
- #define CLOCKS_PER_SEC 100
- typedef long clock_t;
- struct tm
- {
- 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;
- };
- /* 确定处理器使用时间。返回程序所使用处理器时间(滴答数)的近似值*/
- clock_t clock(void);
- /* 取时间(秒数).返回自1970.1.1:0:0:0开始的秒数(成为日历时间) */
- time_t time(time_t * tp);
- /* 计算时间差。 */
- double difftime(time_t t1,time_t t2);
- /* 将tm结构表示的时间转化成日历时间 */
- time_t mktime(struct tm *tmp);
- /* 将tm结构表示的时间转换成一个字符串 */
- char *asctime(const struct tm *tmp);
- /* 将日历时间转换成一个字符串形式 */
- char *ctime(const time_t * tp);
- /* 将日历时间转换成tm结构表示的时间(UTC) */
- struct tm * gmtime(const time_t *tp);
- /* 将日历时间转换成tm结构表示的指定时区的时间 */
- struct tm * localtime(const time_t *tp);
- /* 将tm结构表示的时间利用格式字符串fmt转换成最大长度为smax的字符串并存储在s中 */
- size_t strftime(char *s,size_t smax,const char *fmt,const struct tm *tmp);
- /* 初始化时间转换信息,使用环境变量TZ,对zname变量进行初始化。在与时区相关的时间转换中自动调用该函数 */
- void tzset(void);
- #endif
- #include<time.h>
- #include<stdio.h>
- int main()
- {
- clock_t ct;
- ct = clock();
- printf("clocks:%ld/n",ct);
- time_t tt;
- time(&tt); /* 获取日历时间 */
- printf("tt -- %ld/n",tt);
- printf("ctime:/t/t%s/n",ctime(&tt)); /* 打印日历时间的字符串形式 */
- struct tm *tmp;
- tmp = gmtime(&tt); /* 将日历时间转换成tm结构表示的时间 */
- printf("tm_sec:/t%d/n",tmp->tm_sec);
- printf("tm_min:/t%d/n",tmp->tm_min);
- printf("tm_year:/t%d/n",tmp->tm_year);
- char *str = asctime(tmp); /* 将tm结构时间转换成字符串 */
- printf("asctime:/t%s/n",str);
- return 0;
- }