工作中遇到的函数:

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. HP新学知识

    Oracle的框架中有webservice和portlet....但不是平时所知道的那种webservice

  2. oracle 11g 新特性UTL_TCP、UTL_HTTP 和 UTL_SMTP程序包发邮件

    首先,创建一个 ACL: begindbms_network_acl_admin.create_acl (acl             => 'utlpkg.xml', ---创建的访问控制列 ...

  3. The user operation is waiting for "Building workspace" to complete

    1.选择菜单栏的“Project”,然后把菜单栏中“Build Automatically”前面的对钩去掉. 2.当你修改或添加代码后,选择菜单栏的“Project”,然后选择菜单栏中“Build A ...

  4. Java多线程实践

    1.实现Runnable接口 import java.util.Random; public class PrintTask implements Runnable{ private final in ...

  5. HDU 1231 最大连续子序列(水题)

    题目链接: 传送门 最大连续子序列 Time Limit: 1000MS     Memory Limit: 32768 K Description 给定K个整数的序列{ N1, N2, ..., N ...

  6. HDU 1535 Invitation Cards(最短路 spfa)

    题目链接: 传送门 Invitation Cards Time Limit: 5000MS     Memory Limit: 32768 K Description In the age of te ...

  7. Js里面的强制类型转换

    js 和 PHP语言一样是弱类型语言.近期我也在看C语言,并没有传说中那么难,既是书中一再强调的指针部分,也没有那么夸张.至少是理论和语法理解起来不是很难.看起来凡是什么东西,不要总是被别人的话迷惑了 ...

  8. ensure LANG and/or LC_* environment variables are set correctly

    Looks like your locale settings are broken or non-existent on that VM, or at least that session on t ...

  9. GMap.NET使用一

    https://greatmaps.codeplex.com/releases/view/20235 从上面网站下载需要的组件dll,也可以下载源码研究,解压后有两个文件夹,如图1所示,根据不同的fr ...

  10. 9.13 JS循环

    循环:循环操作某一个功能(执行某段代码) 四要素: 循环初始值 循环条件 状态改变 循环体       for  穷举     迭代            i++;等价于i=i+1;  ++I;等价于 ...