免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1316 | 回复: 0
打印 上一主题 下一主题

linux 0.11 - /include/time.h [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-12 04:15 |只看该作者 |倒序浏览

               
/* *******************************
* 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
测试程序:
#includetime.h>
#includestdio.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;
}
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/33029/showart_1286752.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP