当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

c语言中time函数的用法

更新:01-04 整理:39baobao.com
字体:

[c语言中调用函数如何返回多个值]建立数组,返回指针。在要返回的两个值类型相同时,可以用创建数组的方式,将要返回的值存在数组中,并返回数组首地址,这样就可以实现返回两个值的效果。需要注意的是,要返回数组首地...+阅读

头文件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#include#includeint 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()得到 所属文件:#include#include#includeint 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获得 所属文件:#include#includeint 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函数获得 所属文件:#include#include#include#includeint 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()得到的时间信息 所属文件:#include#include#include#includechar *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类型 所属文件:#include#include#includeint 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环境下无用途 函数返回: 参数说明: 所属文件:#include#include#includeint main() { time_t td; putenv("TZ=PST8PDT"); tzset(); time(&td); printf("Current time=%s",asctime(localtime(&td))); return 0; }

本文地址:https://www.39baobao.com/show/29_22953.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

C语言可以调用一个函数的返回值到另一个函数中吗你是像这样吗 #include <stdio.h> int f1(int x) { return x+10; } int f2(int x) { x=f1(x); return x; } int main() {&lt;丹龚草夹禺蝗碴伟厂连br /> int a=10; printf("%d...

面向对象的程序设计语言C编写函数完成指定三维数组#include<iostream> #define N 3 #define M 3 using namespace std; void reset(int a[][N]) { int i,j,t; for(i=0;i<N;i++) for(j=i;j<M;j++) { t=a[i][j]; a[i][j]=a[j][...

C语言 sizeof函数测什么具体用法怎么用sizeof()用来测给定的数据类型在内存中占的字节长度; 比如我想知道int类型变量占几个字节 就这样使用:len = sizeof(int) 就可以了,len就是int型变量在内存中字节数; 当然你也可...

c语言里:sizeof怎样用法判断数据类型长度符的关键字 用法: sizeof(类型说明符,数组名或表达式); 或sizeof 变量名 定义: sizeof是C/C++中的一个操作符(operator),简单的说其作用就是返回一个对象或者类型所...

c语言函数用法建议你下一个C语言函数库,在再用的时候也方便查询 以下帮你从C语言函数库中查的 函数名: memset 功 能: 设置s中的所有字节为ch, s数组的大小由n给定 用 法: void *memset(void...

C语言函数用法问题函数原型:int bioskey (int cmd) 说明:bioskey()的函数原型在bios.h中 bioskey()完成直接键盘操作,cmd的值决定执行什么操作。 cmd = 0: 当cmd是0,bioskey()返回下一个在键盘键入的...

C语言if函数用法IF函数一般是指Excel中的IF函数,根据指定的条件来判断其“真”(TRUE)、“假”(FALSE),根据逻辑计算的真假值,从而返回相应的内容。可以使用函数 IF 对数值和公式进行条件检测。 函...

C语言中free函数用法free函数用法释放ptr指向的存储空间。被释放的空间通常被送入可用存储区池,以后可在调用malloc、realloc以及calloc函数来再分配。 free 不管指针指向多大的空间,均可以正确...

c语言div函数用法#include <stdlib.h> #include <stdio.h> #include <math.h> void main( int argc, char *argv[] ) { int x,y; div_t div_result; printf("input x y:"); scanf("%d%d",&x,&y);...