c/c++ 中的日期时间一般用什么数据类型问题

在tc环境下
时间日期函数,函数库为time.h、dos.h  
在时间日期函数里,主要用到的结构有以下几个:  
总时间日期贮存结构tm  

┌──────────────────────┐   
│struct   tm                                                                       │   
│{                                                                                       │   
│   int   tm_sec;   /*秒,0-59*/                                         │   
│   int   tm_min;   /*分,0-59*/                                         │   
│   int   tm_hour;   /*时,0-23*/                                       │   
│   int   tm_mday;   /*天数,1-31*/                                   │   
│   int   tm_mon;   /*月数,0-11*/                                     │   
│   int   tm_year;   /*自1900的年数*/                             │   
│   int   tm_wday;   /*自星期日的天数0-6*/                   │   
│   int   tm_yday;   /*自1月1日起的天数,0-365*/         │   
│   int   tm_isdst;   /*是否采用夏时制,采用为正数*/│   
│}                                                                                       │   
└──────────────────────┘   
日期贮存结构date   
┌───────────────┐   
│struct   date                                       │   
│{                                                           │   
│   int   da_year;   /*自1900的年数*/│   
│   char   da_day;   /*天数*/                 │   
│   char   da_mon;   /*月数   1=Jan*/     │   
│}                                                           │   
└───────────────┘   
时间贮存结构time   
┌────────────────┐   
│struct   time                                           │   
│{                                                               │   
│   unsigned   char   ti_min;   /*分钟*/   │   
│   unsigned   char   ti_hour;   /*小时*/│   
│   unsigned   char   ti_hund;                   │   
│   unsigned   char   ti_sec;   /**/       │   
│                                                                 │   
└────────────────┘ 

double   difftime(time_t   time2,time_t   time1)   
计算结构time2和time1之间的时间差距(以秒为单位)

时间类型是   time_t,   struct   tm;

可以用   localtime   和   gmtime   获取时间,用   difftime   计算时间差,单位为秒。

时间的函数有:asctime,clock,ctime,difftime,gmtime,localtime,stime,time,tzset   等。

补充楼上的一下,
#include   <ctime>
time_t为long:   typedef   long   time_t
其他的楼上的已经说的很好了

展开阅读全文

有关C中数据类型问题

07-11

在C的编译器中的_G_config.h中有这样一句__extension__ typedef unsigned long long _G_ullong;rn其中的long long上类型?? 怎么书上没介绍过这种类型 高手帮忙给解答一下这句话是什么意思rn该文件的代码如下:rn/* AUTOMATICALLY GENERATED; DO NOT EDIT! */ rn#ifndef _G_config_hrn#define _G_config_hrn#define _G_LIB_VERSION "2.8.0"rn#define _G_NAMES_HAVE_UNDERSCORE 1rn#define _G_VTABLE_LABEL_HAS_LENGTH 1rn#define _G_VTABLE_LABEL_PREFIX "___vt_"rn#define _G_USING_THUNKSrn#define _G_VTABLE_LABEL_PREFIX_ID __vt_rn#define _G_HAVE_ST_BLKSIZE 0rnrn#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)rntypedef int _G_int8_t __attribute__((__mode__(__QI__)));rntypedef unsigned int _G_uint8_t __attribute__((__mode__(__QI__)));rntypedef int _G_int16_t __attribute__((__mode__(__HI__)));rntypedef unsigned int _G_uint16_t __attribute__((__mode__(__HI__)));rntypedef int _G_int32_t __attribute__((__mode__(__SI__)));rntypedef unsigned int _G_uint32_t __attribute__((__mode__(__SI__)));rntypedef int _G_int64_t __attribute__((__mode__(__DI__)));rntypedef unsigned int _G_uint64_t __attribute__((__mode__(__DI__)));rn#if __GNUC__ > 2 || __GNUC_MINOR__ >= 8rn__extension__ typedef long long _G_llong;rn__extension__ typedef unsigned long long _G_ullong;rn#endifrn#elserntypedef short /* deduced */ _G_int16_t;rntypedef unsigned short /* deduced */ _G_uint16_t;rntypedef long /* deduced */ _G_int32_t;rntypedef unsigned long /* deduced */ _G_uint32_t;rn#endifrnrntypedef long _G_clock_t;rntypedef unsigned int _G_dev_t;rntypedef _G_llong _G_fpos_t;rntypedef int /* default */ _G_gid_t;rntypedef short _G_ino_t;rntypedef unsigned short _G_mode_t;rntypedef int /* default */ _G_nlink_t;rntypedef long _G_off_t;rntypedef int _G_pid_t;rn#ifndef __PTRDIFF_TYPE__rn#define __PTRDIFF_TYPE__ intrn#endifrntypedef __PTRDIFF_TYPE__ _G_ptrdiff_t;rntypedef int _G_sigset_t;rn#ifndef __SIZE_TYPE__rn#define __SIZE_TYPE__ unsigned intrn#endifrntypedef __SIZE_TYPE__ _G_size_t;rntypedef long _G_time_t;rntypedef int /* default */ _G_uid_t;rntypedef short unsigned int _G_wchar_t;rnrn#define _G_BUFSIZ 512rn#define _G_FOPEN_MAX (20)rn#define _G_FILENAME_MAX (260)rn#if defined (__cplusplus) || defined (__STDC__)rn#define _G_ARGS(ARGLIST) ARGLISTrn#elsern#define _G_ARGS(ARGLIST) ()rn#endifrn#if !defined (__GNUG__) || defined (__STRICT_ANSI__)rn#define _G_NO_NRVrn#endifrn#if !defined (__GNUG__)rn#define _G_NO_EXTERN_TEMPLATESrn#endifrntypedef int /* default */ _G_ssize_t;rntypedef unsigned int _G_wint_t;rntypedef char * _G_va_list;rn#define _G_signal_return_type voidrn#define _G_sprintf_return_type intrn#define _G_HAVE_ATEXIT 1rn#define _G_HAVE_SYS_RESOURCE 0rn#define _G_HAVE_SYS_TIMES 0rn#define _G_HAVE_SYS_SOCKET 0rn#define _G_HAVE_SYS_CDEFS 0rn#define _G_HAVE_SYS_WAIT 0rn#define _G_HAVE_UNISTD 1rn#define _G_HAVE_DIRENT 1rn#define _G_HAVE_CURSES 0rn#define _G_MATH_H_INLINES 0rn#define _G_HAVE_BOOL 1rn#define _G_HAVE_PRINTF_FP 0rn#define _G_HAVE_LONG_DOUBLE_IO 0rn#undef NULLrn#define __need_NULLrn#include rn#endif /* !_G_config_h */ 论坛

C中数据类型的转换

09-04

兄弟姐妹帮个忙,我遇到个问题,想请教大家,先谢谢啦.rn下面的程序中我想要把一些不同类型数据连接在一起然后打印出来,但是输出的结果却和实际值有出入,比如int型51输出的结果却是3,应该是强制转换(char *)行不通(红色标出的那几段都是有问题的),不知道怎么解决或是有其它的方法呢?rnrnconst std::string& CDBOci::Dump(int logMask, const char * inSqlStatement, const CDBBindVar * aBindVar)rnrn int X;rn int V;rn long tmpNumber;rn char numString[20];rn float tmpFloat;rn std::string logString;rnrn if (logMask & LOG_MASK_DUMP_ERROR_SQL) rn SFW_TRACE(logMask, "");rn //QS_TRACE(LOG_MASK_ERROR,"%d\t%s", SQL_INFO," test");rn rn else rn SFW_TRACE(logMask, "");rn rn SFW_TRACE(logMask, inSqlStatement);rn if (aBindVar != NULL) rn for (X = 0; X < aBindVar->varNumber; X++) rn if (aBindVar->varAttr[X].isArray == FALSE) // Not bind arrayrn logString = "";rn logString = logString + " " + aBindVar->varAttr[X].name + " := ";rn // Print out the vaiables by data typern [color=#0000FF]switch (aBindVar->varAttr[X].type) rn case SQLT_INT: //int型rn tmpNumber = *(int*)aBindVar->varAttr[X].placeHolder;rn //itoa(tmpNumber, buffer, 10);rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%s%d", SQL_INFO," SQLT_INT ",(char*)logString.c_str(),tmpNumber); rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + [color=#FF0000](char*)aBindVar->varAttr[X].placeHolder; [/color]rn logString += "%d;";rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpNumber);rn break;rn case SQLT_UIN: // unsigned int 型 rn tmpNumber = *(unsigned int*)aBindVar->varAttr[X].placeHolder;rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%s%d", SQL_INFO," SQLT_UIN ",(char*)logString.c_str(),tmpNumber);rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + [color=#FF0000](char*)aBindVar->varAttr[X].placeHolder[/color];rn logString += "%d;"; rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpNumber);rn break;rn case SQLT_LNG: //long 型rn tmpNumber = *(long*)aBindVar->varAttr[X].placeHolder;rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%s%d", SQL_INFO," SQLT_LNG ",(char*)logString.c_str(),tmpNumber); rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + [color=#FF0000](char*)aBindVar->varAttr[X].placeHolder[/color]; rn logString += "%d;"; rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpNumber);rn break;rn case SQLT_FLT: //float型rn tmpFloat += *(float*)aBindVar->varAttr[X].placeHolder;rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%s%f", SQL_INFO," SQLT_FLT ",(char*)logString.c_str(),tmpFloat); rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + [color=#FF0000](char*)aBindVar->varAttr[X].placeHolder[/color]; rn logString += "%f;";rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpFloat);rn break;rn case SQLT_CHR:rn case SQLT_STR: //string 型rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%s%s", SQL_INFO," SQLT_STR ",(char*)logString.c_str(),(char*)aBindVar->varAttr[X].placeHolder);rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + (char*)aBindVar->varAttr[X].placeHolder;rn logString += "'%s';";rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), (char*)aBindVar->varAttr[X].placeHolder);rn break;rn [/color] rn else // Bind arrayrn //aBindVar->varAttr[X].curTableSize);rn //SFW_TRACE(logMask, "Bind variable is array !!! Skip dump data.");rnrn for (V=0; VvarAttr[X].curTableSize; V++) rn logString = "";rn sprintf(numString,"%d", V);rn logString = logString + " " + aBindVar->varAttr[X].name + " [" + numString + "] := ";rn // Print out the vaiables by data typern switch (aBindVar->varAttr[X].type) rn case SQLT_INT:rn tmpNumber = *(int*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V));rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%d", SQL_INFO,(char*)logString.c_str(),tmpNumber); rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + (char*)aBindVar->varAttr[X].placeHolder; rn logString += "%d;"; rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpNumber);rn break;rn case SQLT_UIN:rn tmpNumber = *(unsigned int*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V));rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%d", SQL_INFO,(char*)logString.c_str(),tmpNumber); rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + (char*)aBindVar->varAttr[X].placeHolder; rn logString += "%d;"; rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpNumber);rn break;rn case SQLT_LNG:rn tmpNumber = *(long*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V));rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%d", SQL_INFO,(char*)logString.c_str(),tmpNumber); rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + (char*)aBindVar->varAttr[X].placeHolder; rn logString += "%d;"; rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpNumber);rn break;rn case SQLT_FLT:rn tmpFloat += *(float*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V));rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%f", SQL_INFO,(char*)logString.c_str(),tmpFloat);rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + (char*)aBindVar->varAttr[X].placeHolder;rn logString += "%f;"; rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), tmpFloat);rn break;rn case SQLT_CHR:rn case SQLT_STR:rn QS_TRACE(LOG_MASK_ERROR,"%d\t%s%s", SQL_INFO,(char*)logString.c_str(),(char*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V)));rn sSQLMsg = sSQLMsg + " " + (char*)logString.c_str() + (char*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V));rn logString += "'%s';";rn SFW_TRACE(logMask, SFW_STRINGDATA(logString), (char*)((long)aBindVar->varAttr[X].placeHolder + (aBindVar->varAttr[X].nextVarSkipSize * V)));rn break;rn rn rn rn rn rnrn return sSQLMsg;rnrn 论坛

C 基础之数据类型问题

01-22

本人菜鸟,提问如下ABC的问题:rnrn整型数据分为int short long ,同时又可按有无符号型分为signed unsigned;rnintrnunsigned int rnshort int rnunsigned short int rnlong int rnunsigned longrnrn实型数据分为float double long double,它存不存在有无符号型呢?即:存不存在如下类型:rnsigned float rnunsigned floatrnsigned double rnunsigned doublernsigned long double rnunsigned long doublernrn[b]我写了个小C,代码如下,执行结果,让我迷惑,还望各位高人指点?[/b]rnrn#includernrnvoid main()rnrnrn int a1;rn signed int a2;rn unsigned int a3;rn rn short int b1;rn signed short int b2;rn unsigned short int b3;rnrn long int c1;rn signed long int c2;rn unsigned long int c3;rnrn float d1;rn signed float d2;rn unsigned float d3;rnrn double e1;rn signed double e2;rn unsigned double e3;rnrn long double f1;rn signed long double f2;rn unsigned long double f3;rn rn char g;rnrn printf("\n int:%d \n signed int:%d \n unsigned int:%d\n",sizeof(a1),sizeof(a2),sizeof(a3));rn rn printf("\n short int:%d \n signed short int:%d \n unsigned short int:%d\n",sizeof(b1),sizeof(b2),sizeof(b3));rn rn printf("\n long int:%d \n signed long int:%d \n unsigned long int:%d\n",sizeof(c1),sizeof(c2),sizeof(c3));rnrn printf("\n float:%d \n signed float:%d \n unsigned float:%d\n",sizeof(d1),sizeof(d2),sizeof(d3));rnrn printf("\n double:%d \n signed double:%d \n unsigned double:%d\n",sizeof(e1),sizeof(e2),sizeof(e3));rnrn printf("\n long double:%d \n signed long double:%d \n unsigned long double:%d\n",sizeof(f1),sizeof(f2),sizeof(f3));rnrn printf("\n char:%d \n",sizeof(g));rnrnrnrn---------------------------------------------------------------------------------------rn执行结果是:rnrn int:4rn signed int:4rn unsigned int:4rnrn short int:2rn signed short int:2rn unsigned short int:2rnrn long int:4rn signed long int:4rn unsigned long int:4rnrn float:4rn signed float:4rn unsigned float:4rnrn double:8rn signed double:4rn unsigned double:4rnrn long double:8rn signed long double:8rn unsigned long double:8rnrn char:1rnPress any key to continuernrnrn rn 论坛

没有更多推荐了,返回首页