免费注册 查看新帖 |

Chinaunix

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

Linux下C语言编程--时间概念 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-18 12:31 |只看该作者 |倒序浏览
1:时间表示
name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1572879403720716&dt=1173586445812&hl=zh-CN&lmt=1173586445&alternate_ad_url=http%3A%2F%2Fwww.qqread.com%2F0000js%2Fgoogle336.htm&prev_fmts=468x15_0ads_al_s&format=336x280_as&output=html&channel=6686853775&url=mk%3A%40MSITStore%3AG%3A%5Ccomputer.CHM%3A%3A%2FLinux%E4%B8%8BC%E8%AF%AD%E8%A8%80%E7%BC%96%E7%A8%8B--%E6%97%B6%E9%97%B4%E6%A6%82%E5%BF%B5-%E7%94%B5%E8%84%91%E6%95%99%E7%A8%8BQQread_com.htm&color_bg=EDF0F5&color_text=000000&color_link=000000&color_url=0000FF&color_border=EDF0F5&ad_type=text_image&cc=17&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_his=5&u_java=true" frameBorder=0 width=336 scrolling=no height=280 allowTransparency>在程序当中,我们经常要输出系统当前的时间,比如我们使用date命令的输出结果.这个时候我们可以使用下面两个函数
#include
time_t time(time_t *tloc);
char *ctime(const time_t *clock);
time函数返回从1970年1月1日0点以来的秒数.存储在time_t结构之中.不过这个函数的返回值对于我们来说没有什么实际意义.这个时候我们使用第二个函数将秒数转化为字符串. 这个函数的返回类型是固定的:一个可能值为. Thu Dec 7 14:58:59 2000 这个字符串的长度是固定的为26
2:时间的测量
有时候我们要计算程序执行的时间.比如我们要对算法进行时间分析.这个时候可以使用下面这个函数.
#include
int gettimeofday(struct timeval *tv,struct timezone *tz);
strut timeval {
long tv_sec; /* 秒数 */
long tv_usec; /* 微秒数 */
};
gettimeofday将时间保存在结构tv之中.tz一般我们使用NULL来代替.
#include
#include


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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP