- 论坛徽章:
- 0
|
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 |
|