c语言中的time()函数有什么作用

#include <time.h>
time_t time( time_t *time );

功能: 函数返回当前时间,如果发生错误返回零。如果给定参数time ,那么当前时间存储到参数time中。

当前时间是从1970年 1月1日零时开始的秒数.

⑵ c语言time_t ,tm都是些什么类型

下面是粘贴的哈,将就着看,time_t ---long tm是结构体。
typedef __kernel_time_t time_t;
typedef long __kernel_time_t;

struct tm {
164 /*
165 * the number of seconds after the minute, normally in the range
166 * 0 to 59, but can be up to 60 to allow for leap seconds
167 */
168 int tm_sec;
169 /* the number of minutes after the hour, in the range 0 to 59*/
170 int tm_min;
171 /* the number of hours past midnight, in the range 0 to 23 */
172 int tm_hour;
173 /* the day of the month, in the range 1 to 31 */
174 int tm_mday;
175 /* the number of months since January, in the range 0 to 11 */
176 int tm_mon;
177 /* the number of years since 1900 */
178 long tm_year;
179 /* the number of days since Sunday, in the range 0 to 6 */
180 int tm_wday;
181 /* the number of days since January 1, in the range 0 to 365 */
182 int tm_yday;
183 }

⑶ c语言time函数怎么用

#include <stdio.h>
#include <time.h>

int main()
{
time_t t1,t2; //分别声明两种使用方式的赋值对象

t1=time(0); //第一种使用方式
time(&t2); //第二种使用方式

printf("t1=%ld\n",t1);
printf("t2=%ld",t2);

return 0;
}

⑷ c语言的time函数用法

当NULL来用的吧,可以传递一个time_t的指针来获取当前时间,如果不传就填NULL,0也可以,这样取返回值也行

⑸ 关于C语言中内置宏__DATE__和 __TIME__

这两个就是字符串常量,当字符串用就行。

__DATE__:当前的编译日期
__TIME__:当前编译时间;

#include<stdio.h>
#include<string.h>
intmain()
{
printf("%s,%s ",__DATE__,__TIME__);
printf("长度DATE=%d,TIME=%d ",strlen(__DATE__),strlen(__TIME__));
return0;
}

⑹ C语言 time()

1 是把一个正整数放进t所在的地址里,这个正整数是1970年1月1日00:00:00(UTC)开始,到目前为止经过的秒数。

2 因为time以两种方式返回结果。一种是你第一道题的,给他一个地址,他把结果写进那个地址。第二种直接返回一个time_t。你可以用这种方法接:time_t t = time(NULL)。这里给他一个空指针就是告诉他不需要以第一种方法返回结果,所以当然他也不会把结果写进空指针,他只是不管这个参数而已。当然只要你乐意你也可以两种一起用。

⑺ c语言中time函数的用法

头文件time.h

@函数名称: localtime
函数原型: struct tm *localtime(const time_t *timer)
函数功能: 返回一个以tm结构表达的机器时间信息
函数返回: 以tm结构表达的时间,结构tm定义如下:
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;
};
参数说明: timer-使用time()函数获得的机器时间

#include <time.h>
#include <stdio.h>
#include <dos.h>
int main()
{
time_t timer;
struct tm *tblock;
timer=time(NULL);
tblock=localtime(&timer);
printf("Local time is: %s",asctime(tblock));
return 0;
}

@函数名称: asctime
函数原型: char* asctime(struct tm * ptr)
函数功能: 得到机器时间(日期时间转换为ASCII码)
函数返回: 返回的时间字符串格式为:星期,月,日,小时:分:秒,年
参数说明: 结构指针ptr应通过函数localtime()和gmtime()得到
所属文件: <time.h>

#include <stdio.h>
#include <string.h>
#include <time.h>
int main()
{
struct tm t;
char str[80];
t.tm_sec=1;
t.tm_min=3;
t.tm_hour=7;
t.tm_mday=22;
t.tm_mon=11;
t.tm_year=56;
t.tm_wday=4;
t.tm_yday=0;
t.tm_isdst=0;
strcpy(str,asctime(&t));
printf("%s",str);
return 0;
}

@函数名称: ctime
函数原型: char *ctime(long time)
函数功能: 得到日历时间
函数返回: 返回字符串格式:星期,月,日,小时:分:秒,年
参数说明: time-该参数应由函数time获得
所属文件: <time.h>

#include <stdio.h>
#include <time.h>
int main()
{
time_t t;
time(&t);
printf("Today's date and time: %s",ctime(&t));
return 0;
}

@函数名称: difftime
函数原型: double difftime(time_t time2, time_t time1)
函数功能: 得到两次机器时间差,单位为秒
函数返回: 时间差,单位为秒
参数说明: time1-机器时间一,time2-机器时间二.该参数应使用time函数获得
所属文件: <time.h>

#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
int main()
{
time_t first, second;
clrscr();
first=time(NULL);
delay(2000);
second=time(NULL);
printf("The difference is: %f seconds",difftime(second,first));
getch();
return 0;
}

@函数名称: gmtime
函数原型: struct tm *gmtime(time_t *time)
函数功能: 得到以结构tm表示的时间信息
函数返回: 以结构tm表示的时间信息指针
参数说明: time-用函数time()得到的时间信息
所属文件: <time.h>

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
char *tzstr="TZ=PST8PDT";
int main()
{
time_t t;
struct tm *gmt, *area;
putenv(tzstr);
tzset();
t=time(NULL);
area=localtime(&t);
printf("Local time is:%s", asctime(area));
gmt=gmtime(&t);
printf("GMT is:%s", asctime(gmt));
return 0;
}

@函数名称: time
函数原型: time_t time(time_t *timer)
函数功能: 得到机器的日历时间或者设置日历时间
函数返回: 机器日历时间
参数说明: timer=NULL时得到机器日历时间,timer=时间数值时,用于设置日历时间,time_t是一个long类型
所属文件: <time.h>

#include <time.h>
#include <stdio.h>
#include <dos.h>
int main()
{
time_t t;
t=time();
printf("The number of seconds since January 1,1970 is %ld",t);
return 0;
}

@函数名称: tzset
函数原型: void tzset(void)
函数功能: UNIX兼容函数,用于得到时区,在DOS环境下无用途
函数返回:
参数说明:
所属文件: <time.h>

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
time_t td;
putenv("TZ=PST8PDT");
tzset();
time(&td);
printf("Current time=%s",asctime(localtime(&td)));
return 0;
}

⑻ c语言中time参数

time_t
time(
time_t
*time
);
函数time()返回当前时间,若参数time给定,则当前时间存储在time指针中。
注意,这个参数的类型是time_t
*,即一个指针,如果你传的是0的话,会被自动看成NULL,空指针,肯定是无法保存当前时间的。
所以time()函数的实际功能是:如果参数为0则函数返回值即为结果,若参数不为0,则结果保存在参数中。

⑼ C语言时间函数time_t

电脑cpu的主频太高,一百万次空循环的执行时间太短,所以,difftime(返回时间差)的返回值非常非常小,比如他返回的是0.0002的话,实际上不是0,但是因你输出时,只保留两位小数,后面的不是0的值也没输出,所以你保留两位小数输出的话,肯定是0.00
另外,difftime的返回值是64位整数,太小的话,肯定也是零,说到底还是因为时间差太小的造成的

循环次数加大一些,现在cpu主频都是1-2g的,你设1亿次或者10亿应该才能看到差距
for (i = 100000000; i > 0; --i);
改成1亿次。