Linux下面time.h时间函数总结
来源:互联网 发布:卷皮淘宝客网站源码 编辑:程序博客网 时间:2024/05/17 18:23
time.h是C/C++中的日期和时间头文件。
代码示例
# include <stdio.h> #include <time.h> int main(void) { time_t timer =time(NULL); printf("ctime is %s\n",ctime(&timer)); //得到日历时间 return 0; }从系统时钟获取时间方式
time_t time(time_t* timer) 得到从标准计时点(一般是1970年1月1日午夜)到当前时间的秒数。 clock_t clock(void) 得到从程序启动到此次函数调用时累计的毫秒数。time函数介绍
1、函数名称: 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()函数获得的机器时间 所属文件: <time.h> #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; }2、函数名称: asctime
函数原型: char* asctime(struct tm * ptr) 函数功能: 得到机器时间(日期时间转换为ASCII码) 函数返回: 返回的时间字符串格式为:星期,月,日,小时:分:秒,年 参数说明: 结构指针ptr应通过函数localtime()和gmtime()得到3、函数名称: 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; }4、函数名称: 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: %fseconds",difftime(second,first)); getch(); return 0; }5、函数名称: 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; }6、函数名称: 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; }7、函数名称: 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; }- Linux下面time.h时间函数总结
- Linux下面time.h时间函数总结
- Linux下面time.h时间函数总结
- time.h时间函数
- 日期与时间函数time.h
- 日期与时间函数time.h(续)
- unix/linux 中的time.h 函数
- 时间<time.h>有关
- c\c++ 时间相关函数 include<time.h>
- linux时间函数time和gettimeofday
- time.h 函数说明
- time.h函数
- linux时间函数总结
- linux时间函数总结
- linux 时间函数总结
- linux time.h整理
- time.h获取时间字符串
- time()函数--关于时间函数有用的总结
- jdk中bin目录命令详解
- Android OpenGL ES 简明开发教程五:添加颜色
- Havok Physics 翻译资料
- Android OpenGL ES 简明开发教程六: 真正的3D图形
- Android OpenGL ES 简明开发教程七:材质渲染
- Linux下面time.h时间函数总结
- Django Error
- http://acm.hdu.edu.cn/showproblem.php?pid=3544&&Alice's Game
- 利用this指针实现对象资源的拷贝
- 回调函数
- linux各环境变量配置文件简单总结介绍
- B/S学习心得
- 初识oracle重做日志文件
- windows上的Apache+MySQL+PHP环境搭建