工作中遇到的函数:

int seed = time(NULL);

srand(seed);
signal(SIGINT, stop);
signal(SIGUSR1, sig_usr1);      搜time函数时,看到相关time   函数的文章,粘贴如下:

-------------------------

from:http://blog.csdn.net/wangluojisuan/article/details/7045592

c语言中time函数的用法

标签: 语言ctimerstruct日历null
2011-12-06 12:48 61912人阅读 评论(4) 收藏 举报

 分类:
C语言(3) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

头文件time.h 
@函数名称:     localtime 
函数原型:     struct tm *localtime(const time_t *timer) 
函数功能:     返回一个以tm结构表达的机器时间信息 
函数返回:     以tm结构表达的时间,结构tm定义如下: 
[cpp] view plaincopy
  1. struct  tm{
  2. int tm_sec;
  3. int tm_min;
  4. int tm_hour;
  5. int tm_mday;
  6. int tm_mon;
  7. int tm_year;
  8. int tm_wday;
  9. int tm_yday;
  10. int tm_isdst;
  11. };
参数说明:     timer-使用time()函数获得的机器时间 
[cpp] view plaincopy
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <dos.h>
  4. int main() {
  5. time_t timer;
  6. struct tm *tblock;
  7. timer=time(NULL);
  8. tblock=localtime(&timer);
  9. printf("Local time is: %s",asctime(tblock));
  10. return 0;
  11. }
@函数名称:     asctime 
函数原型:     char* asctime(struct tm * ptr) 
函数功能:     得到机器时间(日期时间转换为ASCII码) 
函数返回:     返回的时间字符串格式为:星期,月,日,小时:分:秒,年 
参数说明:     结构指针ptr应通过函数localtime()和gmtime()得到 
所属文件:     <time.h> 
[cpp] view plaincopy
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. int main() {
  5. struct tm t;
  6. char str[80];
  7. t.tm_sec=1;
  8. t.tm_min=3;
  9. t.tm_hour=7;
  10. t.tm_mday=22;
  11. t.tm_mon=11;
  12. t.tm_year=56;
  13. t.tm_wday=4;
  14. t.tm_yday=0;
  15. t.tm_isdst=0;
  16. strcpy(str,asctime(&t));
  17. printf("%s",str);
  18. return 0;
  19. }
@函数名称:     ctime 
函数原型:     char *ctime(long time) 
函数功能:     得到日历时间 
函数返回:     返回字符串格式:星期,月,日,小时:分:秒,年 
参数说明:     time-该参数应由函数time获得 
所属文件:     <time.h> 
[cpp] view plaincopy
  1. #include <stdio.h>
  2. #include <time.h>
  3. int main() {
  4. time_t t;
  5. time(&t);
  6. printf("Today's date and time: %s",ctime(&t));
  7. return 0;
  8. }
@函数名称:     difftime 
函数原型:     double difftime(time_t time2, time_t time1) 
函数功能:     得到两次机器时间差,单位为秒 
函数返回:     时间差,单位为秒 
参数说明:     time1-机器时间一,time2-机器时间二.该参数应使用time函数获得 
所属文件:     <time.h> 
[cpp] view plaincopy
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <conio.h>
  5. int main() {
  6. time_t first, second;
  7. clrscr();
  8. first=time(NULL);
  9. delay(2000);
  10. second=time(NULL);
  11. printf("The difference is: %f seconds",difftime(second,first));
  12. getch();
  13. return 0;
  14. }
@函数名称:     gmtime 
函数原型:     struct tm *gmtime(time_t  *time) 
函数功能:     得到以结构tm表示的时间信息 
函数返回:     以结构tm表示的时间信息指针 
参数说明:     time-用函数time()得到的时间信息 
所属文件:     <time.h> 
[cpp] view plaincopy
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <dos.h>
  5. char *tzstr="TZ=PST8PDT";
  6. int main() {
  7. time_t t;
  8. struct tm *gmt, *area;
  9. putenv(tzstr);
  10. tzset();
  11. t=time(NULL);
  12. area=localtime(&t);
  13. printf("Local time is:%s", asctime(area));
  14. gmt=gmtime(&t);
  15. printf("GMT is:%s", asctime(gmt));
  16. return 0;
  17. }
@函数名称:     time 
函数原型:     time_t time(time_t *timer) 
函数功能:     得到机器的日历时间或者设置日历时间 
函数返回:     机器日历时间 
参数说明:     timer=NULL时得到机器日历时间,timer=时间数值时,用于设置日历时间,time_t是一个long类型 
所属文件:     <time.h> 
[cpp] view plaincopy
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <dos.h>
  4. int main() {
  5. time_t t;
  6. t=time();
  7. printf("The number of seconds since January 1,1970 is %ld",t);
  8. return 0;
  9. }
@函数名称:     tzset 
函数原型:     void tzset(void) 
函数功能:     UNIX兼容函数,用于得到时区,在DOS环境下无用途 
函数返回: 
参数说明: 
所属文件:     <time.h> 
[cpp] view plaincopy
  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. int main() {
  5. time_t td;
  6. putenv("TZ=PST8PDT");
  7. tzset();
  8. time(&td);
  9. printf("Current time=%s",asctime(localtime(&td)));
  10. return 0;
  11. }

转载于:https://www.cnblogs.com/the-tops/p/5900163.html

c语言中time相关函数相关推荐

  1. c语言中shmget相关函数,unix中共享内存(shmget的实现,非mmap)

    共享内存是系统出于多个进程之间通讯的考虑,而预留的的一块内存区.在/proc/sys/kernel/目录下,记录着共享内存的一些限制,如一 个共享内存区的最大字节数shmmax,系统范围内最大共享内存 ...

  2. c语言中shmget相关函数,共享内存函数(shmget、shmat、shmdt、shmctl)及其范例 - guoping16的专栏 - 博客频道 - CSDN...

    2014年4月2日共享内存函数(shmget.shmat.shmdt.shmctl)及其范例 - guoping16的专栏 - 博客频道 - http://doc.xuehai.net 登录 | 注册 ...

  3. c语言用string类型,c语言中的string

    1. strlen(char const* s); 函数传入的是c风格字符串(即以'\0'结尾的字符数组),返回的长度为size_t(即unsigned int),其长度不包括'\0'. 2. str ...

  4. c语言中用两个n表示什么格式,C语言中‘\n'为什么能表示CRLF两个字节

    为什么要说这个简单的问题? 众所周知,在Windows下文本文件的换行符是CRLF,占两个字节.在Unix下是LF,占一个字节.(还有奇葩的Mac是CR).但是C语言中直接printf一个 '\n', ...

  5. go语言中fmt包中Print、Printf、Println输出相关函数的区别

    go语言中fmt包中Print.Printf.Println输出相关函数的区别 区别: Print系列函数将内容输出到系统的标准输出.其区别:Print函数式直接输出内容,Printf函数支持格式化输 ...

  6. c语言 recv_sin,C++_C语言中经socket接收数据的相关函数详解,recv()函数: 头文件:#incl - phpStudy...

    C语言中经socket接收数据的相关函数详解 recv()函数:头文件: #include #include 定义函数: int recv(int s, void *buf, int len, uns ...

  7. c语言中open函数r,C语言中open函数

    语法Open ( windowvar, windowtype {, parent } ) 参数windowvar:指定窗口变量名,Open()函数把打开窗口的引用放置到该变量中windowtype:s ...

  8. c语言malloc作用,c语言中malloc是什么?怎么用?

    c语言中malloc是什么?怎么用? malloc() 函数用来动态地分配内存空间,其原型为:void* malloc (size_t size); 说明: [参数说明] size 为需要分配的内存空 ...

  9. c语言中open的原理,C语言中open函数

    语法Open ( windowvar, windowtype {, parent } ) 参数windowvar:指定窗口变量名,Open()函数把打开窗口的引用放置到该变量中windowtype:s ...

最新文章

  1. layui学习资料汇总
  2. java 编写命令行工具_编写命令行工具
  3. Spring JDBC 框架一个最简单的Hello World级别的例子
  4. uniapp底部弹出框效果
  5. DiagnosticsTextBox:WinForms的日志窗口
  6. NoSQL数据库之国产开源产品:SequoiaDB 分析前言
  7. java aes文件加密_JAVA AES文件加解密
  8. 高等数学复习要点(期末考试同济版)
  9. mac如何查看ssd寿命_固态硬盘ssd写入量剩余读写次数怎么查
  10. 解决SQLServer2008安装失败最直白的解决方式
  11. linux还原防火墙设置,Linux防火墙设置教程
  12. 艺多不压身 -- 目录
  13. 燕山大学联通新卡绑定校园网
  14. 好男儿当生三国 好女子当养唐朝
  15. 怎么把PicPick设置成中文版?
  16. python,你也和小猪佩奇一样社会了!
  17. xgboost 论文
  18. C#中的ExecuteNonQuery();
  19. 热插拔机制之udev和mdev
  20. 福建闽北卫生学校计算机考试,福建闽北卫生学校

热门文章

  1. oracle 德部分操作笔记(自己用的)
  2. JAVA基础--final、static区别以及类加载顺序
  3. 玩够了没,开始奋斗吧?
  4. Mac 环境 下使用Charles 抓包Http/Https请求
  5. Lombok中关于@Data的使用
  6. Adadelta原文解读
  7. conky在ubuntu xfce4下面的配置
  8. 使用nltk.pos出现IndexError: string index out of range
  9. ubuntu16.04禁用触摸板
  10. 机器学习:正则化原理总结