工作中遇到的函数:

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函数的用法

2011-12-06 12:48 61912人阅读 评论(4) 收藏 举报
 分类:
C语言(3) 

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

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

c语言中time相关函数的更多相关文章

  1. C语言中的isalpha,isdigit,islower,isupper等一系列函数

    TITLE:c语言中的isalpha,isdigit,islower,isupper等一系列函数 已经全部验证检查,无任何错误 isalnum(测试字符是否为英文或数字) 相关函数 isalpha,i ...

  2. C语言中,头文件和源文件的关系(转)

    简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析阶段 3.编译阶段,首先编译成纯汇编语句, ...

  3. C 语言中 setjmp 和 longjmp

    在 C 语言中,我们不能使用 goto 语句来跳转到另一个函数中的某个 label 处:但提供了两个函数——setjmp 和 longjmp来完成这种类型的分支跳转.后面我们会看到这两个函数在处理异常 ...

  4. c语言中的scanf在java中应该怎么表达,Scanner类。

    1 java是面向对象的语言 它没有像C语言中的scanf()函数,但是它的类库中有含有scanf功能的函数 2 java.util包下有Scanner类 Scanner类的功能与scanf类似 3 ...

  5. C语言中do...while(0)的妙用(转载)

    转载来自:C语言中do...while(0)的妙用,感谢分享. 在linux内核代码中,经常看到do...while(0)的宏,do...while(0)有很多作用,下面举出几个: 1.避免goto语 ...

  6. C语言中,定义的含义?声明的含义?它们之间的区别是什么?

    在C语言中,对于定义和声明,也许我们非常的熟悉,但不一定真正的了解! 定义的含义:所谓定义,就是创建(编译器)一个对象,为这个对象分配一块内存空间并取名,也就是我们平常所说的变量名或对象名,一旦这个名 ...

  7. C++中函数的默认参数和C语言中volatile的学习

    1.函数默认参数 1 int func(int a,int b=10) 2 { 3 return a*b; 4 } 5 6 int main() 7 { 8 int c=func(2); 9 cout ...

  8. C语言中qsort函数用法

    C语言中qsort函数用法-示例分析    本文实例汇总介绍了C语言中qsort函数用法,包括针对各种数据类型参数的排序,非常具有实用价值非常具有实用价值. 分享给大家供大家参考.C语言中的qsort ...

  9. C语言中的static 详细分析

    转自:http://blog.csdn.net/keyeagle/article/details/6708077/ google了近三页的关于C语言中static的内容,发现可用的信息很少,要么长篇大 ...

随机推荐

  1. Leetcode 132. Palindrome Partitioning II

    求次数的问题一般用DP class Solution(object): def minCut(self, s): """ :type s: str :rtype: int ...

  2. 【BZOJ-1040】骑士 树形DP + 环套树 + DFS

    1040: [ZJOI2008]骑士 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3312  Solved: 1269[Submit][Status ...

  3. 【BZOJ-1468】Tree 树分治

    1468: Tree Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1025  Solved: 534[Submit][Status][Discuss] ...

  4. USACO 3.4 Electric Fence 皮克定理

    题意:在方格纸上画出一个三角形,求三角形里面包含的格点的数目 因为其中一条边就是X轴,一开始想的是算出两条边对应的数学函数,然后枚举x坐标值求解.但其实不用那么麻烦. 皮克定理:给定顶点坐标均是整点( ...

  5. 更改codeblocks的配色方案

    codeblocks默认只有一种配色方案, 不过我们可以手动添加. 在终端下输入如下命令: cd ~/.codeblocks sudo gedit default.conf 在打开的配置文件中, 找到 ...

  6. TYVJ1427 小白逛公园

    时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述     小新经常陪小白去公园玩,也就是所谓的遛狗啦…在小新家附近有一条“公园路”,路的一边从南到北依次排着n个 ...

  7. nagios note

    server: nagios nagios_plugin nrpe ip:192.168.1.2 client nagios_plugin xinetd nrpe ip:192.168.1.3 一篇介 ...

  8. ObjC 利用反射和KVC实现嵌套对象序列化成JSON数据

    原理: 0.创建一个新的可变字典:NSMutableDictionary 1.采用class_copyPropertyList函数遍历对象的属性 2.property_getName获取属性名,val ...

  9. PHP扩展——C扩展实现滚动记录日志

    前言 万事开头难,没错就是这样!! 在没有真正开发PHP扩展之前,一直觉得PHP扩展开发对我来说是一个很遥远的事情,虽然自己有些C\C++基础,但是看PHP源码的时候还是很吃力,现在看来主要还是没有下 ...

  10. sed命令给文本文件的每行的行首或者行尾添加文字

    在每行的头添加字符,比如"HEAD",命令如下: sed 's/^/HEAD&/g' test.file 在每行的行尾添加字符,比如“TAIL”,命令如下: sed 's/ ...