time
						
						函数
				
		
		
				
						
						
								 
						
				
		
		
				
						
								       time_t    tTime1 = 0;
				
		
		
				
						
								       time_t    tTime2 = 0;
				
		
		
				
						
								       time_t    tTime3 = 0;
				
		
		
				
						
								       struct tm      *pTime = NULL;
				
		
		
				
						
								       struct tm      sTime = {0};
				
		
		
				
						
								       size_t            timeLen = 0;
				
		
		
				
						
								       
						
				
		
		
				
						
								       time(&tTime1);                    //
				
				以秒为单位获得当前系统时间,
				
						int
				
				型
		
		
				
						
								       tTime2 = time(NULL);
				
		
		
				
						    tTime3 = mktime(&sTime);         //
				
				转换本地时间为日历值,若当地时间在
				
				
						
								1970
						
						年
						
								1
						
						月
						
								1
						
						日
				
				
						               //
				
				午夜之前,则返回
				
						time_t
				
				类型的
				
						-
				
				1
		
		
				
						
								                                    //
				
				其实是把秒数转为年月日时分秒
		
		
				
						
								 
						
				
		
		
				
						   ptime = localtime(&tTime2);     //
				
				把一个时间数据转换为当地时区的时间,若时间在
		
		
				
						               //
						
								1970 
								
										年
								
								1
								
										月
								
								1
						
				
				日之前,返回
				
						NULL
				
		
		
				
						
								       
						
				
		
		
				
						
								       timeLen = strftime( strTime,
				
				
						                           33, 
				
				
						                           "%Y(Y)%m(M)%d(D)%H(H)%M(M)%S(S)",
                           
				
				
						pTime);                  //
				
				格式化一个时间字符串
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								strftime()
						
				
		
		
				格式化一个时间字符串
		
		
				
						size_t     strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr );
				
		
		
				
						
								 
						
				
		
		
				这个例子中将以“星期
				
						-
				
				日
				
						-
				
				月
				
						-
				
				年”的格式显示当前日期:
				
						
								     
						
				
		
		
				
						time_t   LocalTime;    
				
		
		
				
						struct     tm *Today;    
				
		
		
				
						char     Buffer[150],  Format[]="
				
				今天的日期是:
				
						%A %d %B %Y";     
				
		
		
				
						time(&LocalTime);      
				
		
		
				
						Today=localtime(&LocalTime);     
				
		
		
				
						strftime(Buffer,150,format
				
				,
				
						Today);   
				
		
		
				
						cout<<Buffer;
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								_strtime()
						
				
		
		
				把当前时间复制到缓冲区中,
		
		
				
						char *_strtime( char *timestr );
				
		
		
				
						
								 
						
				
		
		
				这个例子中获取了当前时间:
				
						
								  
						
				
		
		
				
						char buffer[10];   
				
		
		
				
						_strtime(buffer);  
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								time()
						
				
		
		
				以秒为单位获取系统时间
		
		
				
						time_t time( time_t *timer );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								_utime()
						
				
		
		
				为文件设置修改时间,若成功则返回0,否则返回
				
						-1
				
		
		
				
						int _utime( unsigned char *filename, struct _utimbuf *times );
				
		
		
				
						
								 
						
				
		
		
				这个例子中把文件
				
						sample.txt
				
				的修改时间变成当前的系统时间:   
		
		
				
						system("dir sample.txt");   
				
		
		
				
						_utime("sample.txt",NULL);   
				
		
		
				
						system("dir sample.txt");
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								asctime()
						
				
		
		
				把
				
						tm
				
				型的变量转换为一个字符串
		
		
				
						char *asctime( const struct tm *timeptr );
				
		
		
				
						
								 
						
				
		
		
				得到系统当前日期和时间:
				
				
		
		
				
						time_t Elapse;  
				
		
		
				
						struct tm *Now;  
				
		
		
				
						time(&Elapse);  
				
		
		
				
						Now=locatime(&Elapse);  
				
		
		
				
						cout<<"
				
				当前的日期和时间为:
				
						"<<asctime(Now);
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								ctime()
						
				
		
		
				把一个
				
						time_t
				
				型的时间值转换为一个字符串,并且根据当地的时区设置对字符串进行调整
		
		
				
						char *ctime( const time_t *timer );
				
		
		
				
						
								 
						
				
		
		
				这个例子中可以显示当地时间:
				
						
								   
						
				
		
		
				
						time_t ltime;  
				
		
		
				
						time(<ime);    
				
		
		
				
						printf( "The time is %s\n", ctime( <ime ) );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								difftime()
						
				
		
		
				返回两个
				
						time_t
				
				型变量之间的时间间隔
		
		
				
						double difftime( time_t timer1, time_t timer0 );
				
		
		
				
						
								 
						
				
		
		
				这个例子中实现了计算电脑执行
				
						100
				
				万次
				
						for
				
				语句所需的时间:
				
						
								    
						
				
		
		
				
						clock_t Start,Finish;     
				
		
		
				
						long  n=1000000L;   
				
		
		
				
						double Elapse;   
				
		
		
				
						time(&Start);   
				
		
		
				
						for( ; n--; ) { ; }   
				
		
		
				
						time(&Finish);    
				
		
		
				
						Elapsed= difftime(Finish,Start);
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								_ftime()
						
				
		
		
				返回当前时间
		
		
				
						void _ftime( struct _timeb *timeptr );
				
		
		
				这个例子中把当前时间的信息写入结构
				
						timebuffer
				
				中:
				
						
								   
						
				
		
		
				
						struct_time timebuffer;   
				
		
		
				
						char *p;   
				
		
		
				
						_ftime(&timebuffer);    
				
		
		
				
						p=ctime(&(timebuffer.time));
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								_futime()
						
				
		
		
				为某个已经打开的文件设置修改时间,若成功则返回
				
						0
				
				,否则返回
				
						-1
				
		
		
				
						int _futime( int handle, struct _utimbuf *filetime );
				
		
		
				这个例子中使用了
				
						_futime
				
				函数来把当前的系统时间设置为文件修改的时间:
				
						
								     
						
				
		
		
				
						int hFile;  
				
		
		
				
						system("dir futime.c");   
				
		
		
				
						hFile=_open("futime.c",_o_RDWR);   
				
		
		
				
						if( _futime(hFile,NULL)==-1)   
				
		
		
				
						perror("_futime failed\n");    
				
		
		
				
						else   
				
		
		
				
						printf( "File time modified\n");   
				
		
		
				
						close (hfile);    
				
		
		
				
						system("dir futime.c");
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								gmtime()
						
				
		
		
				把一个
				
						time_t
				
				类型的数据转换为
				
						tm
				
				类型
		
		
				
						struct tm *gmtime( const time_t *timer );
				
		
		
				这个例子中实现了以“星期、年月日、时分秒”的形式显示当前时间:   
		
		
				
						long LocalTime;    
				
		
		
				
						struct tm *GlobalTime;   
				
		
		
				
						time(&LocalTime);   
				
		
		
				
						GlobalTime=gmtime(&LocalTime);   
				
		
		
				
						cout<<asctime(GlobalTime);
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								localtime()
						
				
		
		
				把一个时间数据转换为当地时区的时间,若时间在
				
						
								1970
						
						年
						
								1
						
						月
						
								1
						
						日
				
				之前,返回
				
						NULL
				
		
		
				
						struct tm *localtime( const time_t *timer );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								mktime()
						
				
		
		
				转换本地时间为日历值,若当地时间在
				
						
								1970
						
						年
						
								1
						
						月
						
								1
						
						日午夜前
				
				,则返回
				
						time_t
				
				类型的
				
						-
				
				1
		
		
				
						time_t mktime( struct tm *timeptr );
				
		
		
				这个例子将显示当前的时间和日期: 
		
		
				
						time_t Now,Result;  
				
		
		
				
						struct  tm LocalTime;   
				
		
		
				
						time(&Now);   
				
		
		
				
						LocatTime-*locatimt(&Now);  
				
		
		
				
						Result=mktime(&LocalTime);  
				
		
		
				
						cout<<"
				
				当前的时间和日期是:
				
						"<<asctime(&LocalTime);
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						_wutime()
				
		
		
				为一个文件设置修改时间,若成功则返回
				
						0
				
				,否则返回
				
						-1
				
				,本函数只适用于宽字符编程
		
		
				
						int _wutime( wchar_t *filename, struct _utimbuf *times );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								_wstrtime()
						
				
		
		
				把当前时间复制到缓冲区中,本函数只适用于宽字符编程
		
		
				
						wchar_t *_wstrtime( wchar_t *timestr );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								_wctime()
						
				
		
		
				把一个
				
						time_t
				
				型的时间值转换为一个字符串,并且根据当地的时区设置对字符串进行调整
		
		
				
						wchar_t *_wctime( const time_t *timer );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								wcsftime()
						
				
		
		
				格式化一个时间字符串
		
		
				
						size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr );
				
		
		
				
						
								 
						
				
		
		
				
						
								 
						
				
		
		
				
						
								wasctime()
						
				
		
		
				把
				
						tm
				
				型的变量转换为一个宽字符串
		
		
				
						wchar_t *_wasctime( const struct tm *timeptr );
				
		
		
				
						
								 
						
				
		
		
				
						转换取系统时间为在数据库中取时间
						
								
								
						
				
		
		
				
						
								 
						
				
		
		
				
						
								       char cTime[] = {0};
				
		
		
				
						
								       long nTime = 0;
				
		
		
				
						
								       DADBHandle      handle;
				
		
		
				
						
								       time_t    t_time;
				
		
		
				
						#if 0
				
		
		
				
						
								       time(&t_now);
				
		
		
				
						
								       tp = localtime(&t_now);
				
		
		
				
						
								       ncurmin = tp->tm_min;
				
		
		
				
						
								       ncurhour = tp->tm_hour;
				
		
		
				
						#else
				
		
		
				
						
								       rv = DB_ConnGet(&handle, 0, 0);
				
		
		
				
						
								       if(DAESQLDB_OK != rv)
				
		
		
				
						
								       {
				
		
		
				
						
								              LOG_ERR("err DA_EsqlDB_ConnGet")  
				
		
		
				
						
								       }
				
		
		
				
						
								       rv = DB_GetDBTime(handle, cTime);
				
		
		
				
						
								       if(DAESQLDB_OK != rv)
				
		
		
				
						
								       {                           
				
		
		
				
						
								              LOG_ERR("err DA_EsqlDB_GetDBTime")
				
		
		
				
						
								       }
				
		
		
				
						
								       rv = DB_ConnFree(handle, 1);
				
		
		
				
						
								       if(DAESQLDB_OK != rv)
				
		
		
				
						
								       {
				
		
		
				
						
								              LOG_ERR("error in DA_EsqlDB_ConnFree")            
				
		
		
				
						
								       }
				
		
		
				
						
								       nTime = atol(cTime);
				
		
		
				
						
								       t_time = time(&nTime);
				
		
		
				
						
								       tp = localtime(&t_time);
				
		
		
				
						
								       ncurmin = tp->tm_min;
				
		
		
				
						
								       ncurhour = tp->tm_hour;
				
		
		
				
						#endif