C中各种系统时间的调用_第1页
C中各种系统时间的调用_第2页
C中各种系统时间的调用_第3页
C中各种系统时间的调用_第4页
C中各种系统时间的调用_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、c+中各种关于系统时间调用1 一个最简单易用的时钟程序,调用系统处理器时间,实现年月日,星期的输出#inelude <iostream.h>#inelude <time.h>#inelude <windows.h> void main()time_t t;while(l)实现循环,不断调用系统时间coutvv'today's date and time:"«endlvvctime(&t)«endl;sleep(looo); system("clsn);延时n秒后刷新清屏,如果无此项,输出时将会是

2、没刷新一次就会印出一个时间2 ”time.h”的一些基本信息time_t和clock_t和size_t都是与long有同等意义得名字。本类别给出时间和日期处理函数。头 文件为time.h。日期和时间函数time_t和clock_t和size_t都是与long有同等意义的名字。 本类知给岀时i'耳和日期瓦理函数头文件time.h函数列表函数类别函数用途详细说明long clock(void);返回程序开始执行后占用的处理器时间。得到时间差delay (int n);表明延时n秒;sleep (int n);延时n秒后刷新;double difftime(long t2,long tl);

3、返回 t2-tl 得值。long mktime (structtm*);将结构体屮的当地时间转换为口历时间。 得到时间longtime (long *tp);返回当前日历时间,同时将返回值赋给*tp; 时间转换函数 得到以ascii码表示的时间char *asctime (const struct tm *tp); 得到字符串表示的时间char *ctime(const time_t *tp);得到指定格式的时间 size_t strftime(char *s,size_t smax,const char *fmt,const struct tm *tp); time.h的原文件为/* tim

4、e.h* this file has no copyright assigned and is placed in the public domain.* this file is a part of the mingw-runtime package.* no warranty is given; refer to the file disclaimer within the package.* date and time functions and types.*/* ifndef_time_h_/define _time_h_/* all the headers include this

5、 file. */include <_mingw.h>#define _n eed_wchar_t#defi ne _need_size_t/define _need_null#ifndef rcjnvoked#inelude <stddef.h>#endif/* not rcjnvoked */* number of clock ticks per second. a clock tick is the unit by which* processor time is measured and is returned by 'clock'.*/#def

6、ine clocks_per_sec (clock_t)1000)#define clk_tck clocks_per_sec#ifndef rc invoked/* a type for storing the current time and date. this is the number of* seconds since midnight jan 1,1970.* note: this is also defined in non-iso sys/types.h.*/* ifndef_time_t_definedtypedef long time_t;#define _time_t_

7、defined#enchf#ifndef _strict_ansi_/* a 64-bit time_t to get to y3k */#ifndef_time64_t_definedtypedef _int64 _time64_t;#define _time64_t_defined* end 讦#endif/* a type for measuring processor time (in clock ticks).*/#ifndef_clock_t_definedtypedef long clock_t;#define _clock_t_defined#enchf#ifndef_tm_d

8、efined/* a structure for storing all kinds of useful information about the* current (or another) time.*/struct tmint tm_sec; /* seconds: 0-59 (k&r says 0-61?) */int tm_min; /* minutes: 0-59 */int tm_hour; /* hours since midnight: 0-23 */int tm_mday; /* day of the month: 1-31 */int tm_mon; /* mon

9、ths *since* january: 0-11 */int tm_year; /* years since 1900 */int tm_wday; /* days since sunday (0-6) */int tm_yday; /* days since jan. 1: 0-365 */int tm_isdst; /* +1 daylight savings time, 0 no dst,* -1 don't know */;/define _tm_defined#enchf#ifdef_cplusplusextern "cn * end 讦_crtimp clock

10、_t _cdecl clock (void);_crtimp time_t _cdecl time (time_t*);_crtimp double _cdecl difftime (time_t, time_t);_crtimp time_t _cdecl mktime (struct tm*);/* these functions write to and return pointers to static buffers that may* be overwritten by other function calls. yikes!* note: localtime, and perha

11、ps the others of the four functions grouped* below may return null if their argument is not 'acceptable1. also note* that calli ng asctime with a null poin ter will produce an in valid page* fault and crap out your program. guess how i know. hint: stat called on* a directory gives 'invalid&#

12、39; times in st_atime etc.*/_crtimp char* _cdecl asctime (const struct tm*);_crtimp char* _cdecl ctime (const time_t*);_crtimp struct tm* _cdecl gmtime (const time_t*);_crtimp struct tm* _cdecl localtime (const time_t*);_crtimp size_t _cdecl strftime (char*, size_t, const char*, const struct tm*); #

13、ifndef _strict_ansi_extern _crtimp void _cdecl _tzset (void);#ifndef_no_oldnamesextern _crtimp void _cdecl tzset (void);#enchf_crtimp char* _cdecl _strdate(char*);_crtimp char* _cdecl _strtime(char*);/* these require newer versions of msvcrt.dll (6.10 or higher). */#讦 _msvcrt_version_ >= 0x0601_c

14、rtimp _time64_t _cdecl _time64( _time64_t);_crtimp _time64_t _cdecl _mktime64 (struct tm*);_crtimp char* _cdecl _ctime64 (const _time64_t*);_crtimp struct tm* _cdecl _gmtime64 (const _time64_t*);_crtimp struct tm* _cdeclocaltime64 (const _time64_t*);#endif/* _msvcrt_version_ >= 0x0601 */* _daylig

15、ht: non zero if daylight savings time is used.* _timez one: d iff ere nee in seconds betwee n gmt and local time.* _tzname: standard/daylight savings time zone names (an array with two* elements).*/#ifdef_msvcrt_/* these are for compatibility with pre-vc 5.0 suppied msvcrt. */extern _crtimp int* _cd

16、ecl _p_daylight (void);extern _crtimp long* _cdecl _p_timezone (void);extern _crtimp char* _cdecl _p_tzname (void);_mingwjmport int _daylight;_mingwmport long _timezone;_mingw_importchar *_tzname2;#else /* not _msvcrt (ie. crtdll) */#ifndef_declspec_supportedextern int* jmpdaylight_dll;ext er n long

17、* jmptimez on e_dll;ext er n char* jmptzname;#define _daylight (*_impdaylight_dll)#define _timezone (*_imptimezone_dll)#define _tzname (*mptzname)#else /* _declspec_supported */_mingwmport int _daylight_dll;_mingwjmport long _timezone_dll;_mingwmport char* _tzname2;#defi ne _daylight _daylight_dll#

18、defi ne _timez one _timez on e_dll#endif/* _declspec_supported */#endif/* not_msvcrt_ */#ifndef_no_oldnames#ifdef_msvcrt_/* these go in the oldnames import library for msvcrt. */_mingwmport int daylight;_mingw_import long timezone;_mingwmport char *tzname2;#else /* not _msvcrt_ */* crtdll is royally

19、 messed up when it comes to these macros.todo: import and alias these via oldnames import library insteadof macros */#define daylight _daylight/* note: timezone not defined because it would conflict with sys/timeb.h.also, tzname used to a be macro, but now it's in moldname. */_mingw_import char

20、*tzname2;#endif/* not_msvcrt_ */#end讦/* not_no_oldnames */#endif/* not _strict_ansi_ */#ifndef_wtime_defined/* wide function prototypes, also declared in wchar.h */#ifndef _strict_ansi_#ifdef_msvcrt_crtimp wchar_t* _cdecl _wasctime(const struct tm*);_crtimp wchar_t* _cdecl _wctime(const time_t*);_cr

21、timp wchar_t* _cdecl _wstrdate(wchar_t*);_crtimp wchar_t* _cdecl _wstrtime(wchar_t*);#讦 _msvcrt_version_ >= 0x0601_crtimp wchar_t* _cdecl _wctime64 (const _time64_t*);# end 讦#endif/*_msvcrt_*/#endif/* _strict_ansi_ */_crtimp size_t _cdecl wcsftime (wchar_t*, size_t, const wchar_t*, const struct t

22、m*);#define_wtime_defined#endif/* _wtime_defined */#ifdef_cplusplus#endif#endif/* not rcjnvoked */#end讦/* not_time_h_*/3. c语言-time.h从头学本文从介绍基础概念入手,探讨了在c/c+中对日期和时间操作所用到的数据结构和函数, 并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你 展示了 time.h头文件中声明的各种函数和数据结构的周详使用方法。关键字:utc (世界标准时间),calendar time (日历时间),epoch (时

23、间点),clock tick (时 钟计时单元)概念在c/c+中,对字符串的操作有非常多值得注意的问题,同样,c/c+对时间的操作也有许多值得 大家注意的地方。最近,在技术群中有非常多网友也多次问到过c+语言中对时间的操作、获取和显示等等的问题。下面,在这篇文章中,笔者将主要介绍在c/c+ 中时间和口期的使用方法.通过学习许多c/c+库,你能有非常多操作、使用时间的方法。但在这之前你需要了解一些 “时间”和“日期”的概念,主要有以下几个:coordinateduniversal time (utc):协调世界时,又称为世界标准时间,也就是大家所熟知的格林威治标 准时间(greenwich me

24、antime, gmt)。比如,中国内地的时间和utc的时差为+8,也就是utc+8。美国是utc5。cale ndartime: h历时间,是用“从一个标准时间点到此时的时间经过的秒数”来表示的时间。这个 标准时间点对不同的编译器来说会有所不同,但对一个编译系统来说,这个标准时间点是不变的,该编译系统中的时间对应的日历时间都通过该标准时间点来 衡量,所以能说口历时间是“相对时间”,不过无论你在哪一个时区,在同一时刻对同一个标准时间点来说,日历时间都是相同的。epoch:时间点。时间点在标准c/c+中是个整数,他用此时的时间和标准时间点相差的秒数 (即日历时间)来表示。clock tick:时

25、钟计时单元(而不把他叫做时钟滴答次数),一个时钟计时单元的时间长短是由 cpu控制的。一个clocktick不是cpu的一个时钟周期,而是c/c+的一个基本计时单位。我们能使用ansi标准库中的time.h头文件。这个头文件中定义的时间和日期所使用的方法, 无论是在结构定义,还是命名,都具有明显的c语言风格。下面,我将说明在c/3+中怎样使用 日期的时间功能。.计时c/c+中的计时函数是clock(),而和其相关的数据类型是clock_to在msdn中,查得对clock 函数定义如下:clock_t clock( void );这个函数返回从“开启这个程式进程”到“程式中调用clock()函数

26、”时之间的cpu时钟计时单 元(clocktick)数,在msdn屮称之为挂钟时间(wal-clock)o其中clock_t是用来保存时间的数据类型, 在time.h文件中,我们能找到对他的定义:#ifndef_clock_t_definedtypedef long clock_t;#define _clock_t_defined#enchf非常明显,clock_t是个长整形数。在time.h文件中,还定义了一个常量clocks_per_sec, 他用来表示一秒钟会看多少个时钟计时单元,其定义如下:#define clocks_per_sec (clock_t)1000)能看到每过千呑z秒(1

27、毫秒),调用clock ()函数返回的值就加1。下面举个例子,你能 使用公式clock()/clocks_per_sec来计算一个进程自身的运行时间:void elapsed_time()printf("elapsed time:%u secs. n"/clock()/clocks_per_sec);当然,你也能用clock函数来计算你的机器运行一个循环或处理其他事件到底花了多少时间:include "stdio.h"include "stdlib.h"#include "time.h"int main( void

28、 )long i = 10000000l;clock_t start, finish;double duration;/*测量一个事件持续的时间*/printf( "time to do %ld empty loops is i);start = clock();while( i-);finish = clock();duration = (double)(finish - start) / clocks_per_sec;printf( n%f seconds n", duration );system("pause");在笔者的机器上,运行结果如下:t

29、ime to do 10000000 empty loops is 0.03000 seconds上而我们看到时钟计时单元的长度为1毫秒,那么计时的精度也为1毫秒,那么我们可不能 通过改动clocks_per_sec的定义,通过把他定义的大一些,从而使计时精度更高呢?通过尝试, 你会发现这样是示行庙。在标准c/c+中,最小的计时单位是一毫秒。.和日期和时间相关的数据结构在标准c/c+屮,我们可通过tm结构來获得口期和时间,tm结构在time.h屮的定义如下:#ifndef_tm_definedstruct tm int tm_sec; /* 秒?取值区间为0,59 */int tm_min;

30、/* 分-取值区间为0,59 */inttm_hour; /* 时-取值区间为0,23 */inttm_mday; /* 一个月中的日期-取值区间为1,31 */inttm_mon;/*月份(从一月开始,0代表一月)取值区间为0,11 */int tm_year; /*年份,其值等于实际年份减去1900 */inttm.wday; /*星期?取值区间为0,6,其中0代表星期天,1代表星期一,以此类推*/int tm.yday; /*从每年的1月1日开始的天数?取值区间为0,365,其中0代表1月1日, 1代表1月2日,以此类推*/int tmjsdst; /*夏令时标识符,实行夏令时的时候,t

31、msdst为正。不实行夏令时的进候, tmjsdst为0;不了解情况时,tm_isdst()为负。*/;#define_tm_defined#end 讦ansi c标准称使用tm结构的这种时间表示为分解时间(broken-down time)。而日历时间(calendartime)是通过time_t数据类型来表示的,用time_t表示的时间(日历 时间)是从一个时间点(例如:1970年1月1日0时0分0秒)到此时的秒数。在time.h中, 我们也能看到是个长整型数:#ifndef_time_t_definedtypedef long time_t; /* 时间值 */#define _time

32、_t_defined /* 避免重复定义 time_t */#enchf大家可能会产生疑问:既然实际上是长整型,到未来的某一天,从一个时间点(一般是 1970年1月1日0时0分0秒)到那时的秒数(即日历时间)超出了长整形所能表示的数的范围怎么办?对time.t数据类型的值來说,他所表示的时间不 能晚于2038年1月18 h 19时14分07秒。为了能够義示更久远的时间,一些编译器厂商引入了 64位甚至更长的整形数来保存日历时间。比如微软 在 visualc+中采用了_time64_t数据类型来保存日历时间,并通过_time64()函数来获得日历时间(而 不是通过使用32位字的time()函数)

33、,这样就能通过该数据类型保存3001年1月1日0时0分0秒(不包括该时间点)之前 的时间。在time.h头文件中,我们还能看到一些函数,他们都是以time.t为参数类型或返回值类型的 函数:double difftime(time_t timel, time_t timeo);time_t mktime(struct tm * timeptr);time_t time(time_t * timer);char * asc廿me(const struct tm * timeptr);char * ctime(const time_t *timer);此外,time.h还提供用种不同的函数将口历时

34、间(一个用表示的整数)转换为我们 平时看到的把年月口时分秒分开显示的时间格式trrnstruct tm * gmtime(const time_t *timer);struct tm * localtime(const time_t * timer);通_过查阅msdn,我们能知道microsoft c/c+7.0屮时间点的值(timej对象的值)是从1899年12月31 口 0时0分0秒到该时间点所经 过的秒数,而其他各种版本的microsoftc/c+和所有不同版本的visual c+都是计算的从1970年1月1日0时0分0秒到该时间点 所经过的秒数。.和日期和时间相关的函数及应用在本节,

35、我将向大家展示怎样利用time.h +声明的函数对时间进行操作。这些操作包括取当 前时间、计算时间间隔、以不同的形式显示时间等内容。4.1获得日历时间我们能通过time()函数来获得日历时间(calendartime),其原型为:time_t time(time_t * timer);如果你已声明了参数timer,你能从参数timer返回目前的日历时间,同时也能通过返回值返回 目前的口历时间,即从一个时间点(例如:1970年1月1日0时0分0秒)到目前此时的秒数。如果参数为空(nul),函数将只通过返回值返 回目前的日历时间,比如下面这个例子用来显示当前的日历时间:include "

36、time.h"#include "stdio.h"int main (void)struct tm *ptr;time_t it;it =time(nul);printf("the calendar time now is %d n",lt);return 0;运行的结果和当时的时间有关,我当时运行的结果是:the calendar time now is 1122707619其中1122707619就是我运行程式时的口历时间。即从1970年1月1日0时0分0秒到此时 的秒数。4.2获得日期和时间这里说的日期和时间就是我们平时所说的年、月、日、

37、时、分、秒等信息。从第2节我们己 知道这些信息都保存在一个名为tm的结构体中,那么怎么将一个f1历时间保存为一个tm结构的 对象呢?其中能使用的函数是gmtime()和localtime(),这两个函数的原型为:struct tm * gmtime(const time_t *timer);struct tm * localtime(const time_t * timer);其中gmtime()函数是将日历时间转化为世界标准时间(即格林尼治时间),并返回一个tm结构 体来保存这个时间,而localtime()函数是将日历时间转化为本地时间。比如目前用gmtimeo函数获得的世界标准时间是20

38、05年7月30 b 7 点18分20秒,那么我用localtime()函数在中国地区获得的本地时间会比世界标准时间晚8个小时,即2005年7月30日15点18分20 秒。下面是个例子:#include "time.h"#include "stdio.h"int main (void)struct tm *local;time 11;t=time(nul);local=localtime(&t);printf(hlocal hour is: %d n",local->tm_hour);local=gmtime(&t);pri

39、ntf("utc hour is: %d n"jocal->tm_hour);return 0;运行结果是:local hour is: 15utchouris:74.3固定的时间格式我们能通过asctimeo函数和ctime()函数将时间以固定的格式显示出来,两者的返回值都是 char*型的字符串。返回的时间格式为:星期儿月份日期 时:分:秒 年n0例如:wed jan 02 02:03:55 1980 n0其中n是个换行符,0是个空字符,表示字符串结束。下面是两个函数的原型:char * asctime(const struct tm * timeptr);cha

40、r * ctime(const time_t *timer);其中asctime()函数是通过tm结构来生成具有固定格式的保存时间信息的字符吊,而ctime()是 通过日历时间来生成时间字符串。这样的话,asctime ()函数只是把tm结构对象中的各个域填到时间字符串的相应位置就行了,而ctime ()函数需要先参照本地的时间设置,把日历时间转化为本地时间,然后再生成格式化后的字符串。在下面,如果t是个非空的变量的话,那 么:printf(ctime(&t);等价于:struct tm *ptr;ptr=localtime(&t);prin tf(asctime(ptr);那

41、么,下面这个程式的两条printf语句输出的结果就是不同的了(除非你将本地时区设为世 界标准时间所在的时区):#include "time.h"#include "stdio.h"int main(void)struct tm *ptr;time_t it;it =time(nul);ptr=gmtime(#includevoid main( void )struct tm ewtime;char tmpbuf128;time_t itl;time( <1);n ewtime=localtime(<l);strftime( tmpbuf, 1

42、28, "today is %a, day %d of %b in the year %y. n", newtime); prin tf(tmpbuf);运行结果:today is saturday, day 30 of july in the year 20054.4计算持续时间的长度有时候在实际应用中耍计算一个事件持续的时间长度,比如计算打字速度。在第1节计时部 分中,我已用clock函数举了一个例子o clocko函数能精确到毫秒级。同时,我们也能使用difftimeo 函数,但他只能精确到秒。该函数的定义如下:double difftime(time_t timel

43、, time_t timeo);虽然该函数返回的以秒计算的时冋间隔是double类型的,但这并不说明该时间具有同double 相同的精确度,这是由他的参数觉得的是以秒为单位计算的)。比如下面一段程式: include "time.hn#include "stdio.h"#include "stdlib.h"int main (void)time_t start, e nd;start = time(nul);system("pause");end = time(nul);prin tf("the pause use

44、d %f sec on ds. n ",difftime(e nd,start);/system("pause");return 0;运行结果为:请按任意键继续the pause used 2.000000 seconds请按任意键继续.能想像,暂停的时间并不那么巧是整整2秒钟。其实,你将上面程式的带有“/<”注释的 一行用下面的一行代码替换:prin tf("the pause used %f sec on ds. n ",end-start); 其运行结果是相同的。4.5分解时间转化为日历时间这里说的分解时间就是以年、月、日、时、分、

45、秒等分量保存的时间结构,在c/c+中是tm 结构。我们能使用mktime ()函数将用tm结构表示的时间转化为日历时间。其函数原型如下:time_t mktime(struct tm * timeptr);其返由值就是转化后的曰历时间。这样我们就能先制定一个分解时间,然后对这个时间进行 操作了,下面的例子能计算出1997年7月1 口是星期几:include "time.hh#include "stdio.h"include "stdlib.h"int main (void)struct tm t;time_t t_of_day;t.tm_yea

46、r=1997-1900;on 二 6;t.tm_mday=l;t.tm_hour=0;t.tm_min=0;t.tm sec=l;t.tm_isdst=o;t_of_day=mktime(&t);prin tf(ctime(&t_of_day);return 0;运行结果:tue jul 01 00:00:01 1997目前注意了,有了 mktime()函数,是不是我们能操作目前之前的所有时间呢?你能通过这种 办法算出1945年8jj 15号是星期几吗?答案是否定的。因为这个时间在1970年1月1日之前, 所以在大多数编译器中,这样的程式虽然能编译通过,但运行时会异常终止。4.

47、 time.h详细操作指南time.h有人总结成这么几句,的确是经典,自己好好编程试试效果吧,两个类型: time_t:表示距离utc时间1970-01-01 00:00:00的秒数。也叫做口历时。 struct tm:通常用于存储本地时。几个函数:time:获取当前系统时间(utc时间)的time_t值。ctime:将time_t值转换为表示本地时间的字符串。 gmttime:将time_t值转换为表示gmt时间的字符吊。localtime:将time_t转换为表示本地时间的strunct tm结构。 mktime:将表示木地时间的struct tm转换为time_t« ascti

48、me:将struct tm转换为字符串形式。difftime:得到两个日历时之间的差值。函数名称: localtime函数原型:struct tm *localtime(const time_t *timer)函数功能:返回一个以tm结构表达的加器时间信息函数返回:以tm结构表达的时间,结构tm定义如下:struct tmint tm_sec; int tm_min; int tm_hour; int tm_mday; int tm mon; int tm_year; int tm_wday; in t tm_yday; int tmjsdst;参数说明:timer-使用time()函数获得的

49、机器时间所属文件:& lt;time.h &gt;#include &lt;time.h&gt;#include &lt;stdio.h&gt;#inelude &lt;dos.h&gt;int main()time t timer;struct tm *tblock;timer=time(null);tblock=localtime( &timer); printf("local time is: %s",asctime(tblock); return 0;函数名称:asctime函数原型:char*

50、 asctime(struct tm * ptr)函数功能:得到机器时间(口期时间转换为ascii码)函数返冋:返回的时间字符串格式为:星期,月,日,小时:分:秒,年参数说明:结构指针ptr应通过函数localtime()和gmtime()得到所属文件:&lt;time.h &gt;#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; int main()struct tm t;char str80;t.tm_sec=l;t.tm ho

51、ur=7;t.tm_mday=22;t.tm_m on 二t.tm_year=56;t.tm_wday=4;t.tm_yday=0; t.tm_isdst=o; strcpy(str,asctime(&t); printf("%s",str);return 0;函数名称:ctime函数原型:char *ctime(long time)函数功能:函数返1 口 1:得到口历时间返回字符串格式:星期,月,日,小时:分:秒,年参数说明:time-该参数应由函数time获得所属文件:&lt;time.h &gt;#include &lt;stdio.h

52、&gt;#include &lt;time.h&gt;int 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 timel)函数功能: 函数返回:得到两次机器时间逹,单位为板 时间差,单位为秒参数说明:timel-机器时间一,time2-机器时间二.该参数应使用time函数获得所属文件:& lt;time

53、.h&gt;#include &lt;time.h&gt;#include &lt;stdio.h&gt;#inelude &lt;dos.h&gt;#include &lt;conio.h&gt;int main()time_t first, second;clrscr();first=time(null);delay(2000);second=time(null);prin tf("the differ ence is: %f sec on ds”,difftime(sec on d,first); getc

54、h();return 0;函数名称:gmtime函数原型:struct tm *gmtime(time_t *time)函数功能:得到以结构tm表示石时间信息函数返回:以结构tm表示的时间信息指针参数说明:time用函数time()得到的时间信息所属文件:& lt;time.h&gt;#inelude &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#inelude &lt;time.h&gt;#include &lt;dos.h&gt;char *tzstr=htz=pst8pdt

55、"int main()time_t t;struct tm *gmt, *area;put en v(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)函数功能: 函数返回:得到几器的日历6寸间或者设置日历时间

56、机器id历时间参数说明:timer=null时得到机器曰历时间,timer=时间数值时,用于设置曰历时间,time_t是一个long类型所属文件:& lt;time.h &gt;#include &lt;time.h&gt;#inelude &lt;stdio.h&gt;#include &lt;dos.h&gt;int main()time_t t;t=time();printf("the number of seconds since january 1,1970 is %ld",t); return 0;

57、函数名称:tzset函数原型:void tzset(void)函数功能:unix兼容函数,用于得到时区,在dos环境下无用途函数返回:参数说明:所属文件:& lt;time.h&gt;#include &lt;time.h&gt;#include &lt;stdlib.h&gt;#include &lt;stdio.h&gt;int main()time_t td;putenv(,tz=pst8pdtn);tzset();time(&td);prin tf("curr ent time=%s",asctime(localtime(&td);return 0;1. coordinated universal time(utc):协调世界时,又称世界标准时间,也即格林威治标准时 间(greenwich mean time,gmt),中国内地的时间与utc得时差为+8,也即utc+8,美国为 utc-5o2. calendar time:日历时间,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论