1. CTime 方法(秒级)
CTime t1 = CTime::GetCurrentTime();
Sleep(xxxx);
CTime t2 = CTime::GetCurrentTime();
CTimeSpan tSp = t2 - t1;
DWORD nSec = tSp.GetTotalSeconds();
// 取得累加上时、分之后所有的秒
// CTime是MFC类库
2. time 方法(秒级)
time_t t1;
time_t t2;
time( & t1);
Sleep(xxxx);
time( & t2);
unsigned tDiff = (unsigned)difftime(t2, t1);
// time_t就是unsigned型
time_t t2;
time( & t1);
Sleep(xxxx);
time( & t2);
unsigned tDiff = (unsigned)difftime(t2, t1);
// time_t就是unsigned型
3. _ftime 方法(毫秒级)
struct
timeb
...
{
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
} ;
struct _timeb tb1;
struct _timeb tb2;
_ftime(tb1);
Sleep(xxxx);
_ftime(tb2);
unsigned nMs = tb2.millitm - tb1.millitm + (tb2.time - tb1.time) * 1000 ;
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
} ;
struct _timeb tb1;
struct _timeb tb2;
_ftime(tb1);
Sleep(xxxx);
_ftime(tb2);
unsigned nMs = tb2.millitm - tb1.millitm + (tb2.time - tb1.time) * 1000 ;
4.取日期
_strdate(
char
buf[]);
//
如:05/03/94
5.取时间
_strtime(
char
buf[]);
//
如:21:51:03
6.附录
struct
timeb
...
{
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
} ;
time_t 就是unsigned型
struct tm ... {
tm_sec, // Seconds after minute (0 – 59)
tm_min, // Minutes after hour (0 – 59)
tm_hour, // Hours since midnight (0 – 23)
tm_mday, // Day of month (1 – 31)
tm_mon, // Month (0 – 11; January = 0)
tm_year, // Year (current year minus 1900)
tm_wday, // Day of week (0 – 6; Sunday = 0)
tm_yday, // Day of year (0 – 365; January 1 = 0)
tm_isdst, // Always 0 for gmtime
} ;
函数 char * ctime( const time_t * timer);
把time_t(逝去的秒数)根据时区,转化为相应的时间的字符串
如: " Apr 29 12:25:12 1994 "
函数 struct tm * gmtime( const time_t * timer);
函数 struct tm * localtime( const time_t * timer);
把time_t(逝去的秒数)转化为“全球时”或“本地时”的tm结构
函数 time_t mktime( struct tm * timeptr);
把tm结构转化为time_t(逝去的秒数)
函数 char * asctime( const struct tm * timeptr);
把tm结构转化为字符串,如 " Sun May 01 20:27:01 1994 "
函数 size_t strftime( char * strDest, size_t maxsize, const char * format, const struct tm * timeptr);
把tm结构格式化,得到想要的某种格式
函数 _tzset
设置环境变量
变量 _tzname
操作全局变量
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
} ;
time_t 就是unsigned型
struct tm ... {
tm_sec, // Seconds after minute (0 – 59)
tm_min, // Minutes after hour (0 – 59)
tm_hour, // Hours since midnight (0 – 23)
tm_mday, // Day of month (1 – 31)
tm_mon, // Month (0 – 11; January = 0)
tm_year, // Year (current year minus 1900)
tm_wday, // Day of week (0 – 6; Sunday = 0)
tm_yday, // Day of year (0 – 365; January 1 = 0)
tm_isdst, // Always 0 for gmtime
} ;
函数 char * ctime( const time_t * timer);
把time_t(逝去的秒数)根据时区,转化为相应的时间的字符串
如: " Apr 29 12:25:12 1994 "
函数 struct tm * gmtime( const time_t * timer);
函数 struct tm * localtime( const time_t * timer);
把time_t(逝去的秒数)转化为“全球时”或“本地时”的tm结构
函数 time_t mktime( struct tm * timeptr);
把tm结构转化为time_t(逝去的秒数)
函数 char * asctime( const struct tm * timeptr);
把tm结构转化为字符串,如 " Sun May 01 20:27:01 1994 "
函数 size_t strftime( char * strDest, size_t maxsize, const char * format, const struct tm * timeptr);
把tm结构格式化,得到想要的某种格式
函数 _tzset
设置环境变量
变量 _tzname
操作全局变量