MFC时间类

MFC时间类

2023年7月17日发(作者:)

时间一般分为两种,一种是本地时间(Local Time),一种是协调世界时间(Coordinated

Universal Time ,UTC),也即格林威治时间。

tm《C运行库中的时间处理函数》

1. The tm structure contains a time stamp or counter

2. struct tm {

int tm_sec;

int tm_min;

int tm_hour;

int tm_mday;

int tm_mon;

int tm_year;//since 1970

int tm_wday;//

value between 0 and 6 that indicates the number of days

since Sunday

int tm_yday; //value between 0 and 365 that indicates the number of days

since January 1

int tm_isdst;

};

3. Header: Include “hbaapi.h”

time_t《C运行库中的时间处理函数》

1. time_t类型为32位或64位整型,具体类型由编译系统决定。此函数用来获得从本地时间1970年1月1日子夜(这个时刻在不同的CRT实现中可能会不一样)到当前时刻以来所流逝的时间,以秒为单位。这个时间差叫做日历时间(Calendar Time )。

2. 通过”time.h”中的time函数获得当前日历时间

3. time_t型的时间方便计算机处理,但不方便普通用户。所以通常将time_t型时间转换成常见的年月日形式,为此定义了tm结构。

4. 常用localtime_s函数将time_t时间转换为tm格式的本地时间。

5. 常用gmtime_s函数将time_t时间转换为tm格式的UTC时间。

6. 将tm表示的时间转换为time_t时间使用mktime函数

CTime《General-purpose time classes, API函数非MFC专有》

1. Represents an absolute time. 2. When object created, set the nDST parameter to 0 to indicate that standard time is in

effect,to a value larger than 0 to indicate that daylight saving time(日光节约时间/夏令时)is in effect

3. tm_isdst is a required field, If not set, its value is undefined and the return value from

mktime is unpredictable

4. Header:”atltime.h”

CTimeSpan《General-purpose time classes, API函数非MFC专有》

1. amount of time, which is internally stored as the number of seconds.

SYSTEMTIME《Windows SDk中提供的时间函数,区别于C运行库中的时间处理函数》

SDK时间比CRT的时间提供了更高的精度。同时SDK提供了更丰富的函数来处理时间

1. SYSTEMTIME与tm类似,不过多了一项wMilliseconds ,如下:

typedef struct _SYSTEMTIME {

WORD wYear;

WORD wMonth;

WORD wDayOfWeek;

WORD wDay;

WORD wHour;

WORD wMinute;

WORD wSecond;

WORD wMilliseconds;

} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;

2. CTime是一个类,其中用到了SYSTEMTIME及FILETIME,SYSTEMTIME 是一个结构

3. 可如下方式取得SYSTEMTIME形式的当前时间

SYSTEMTIME systime; GetSystemTime(&systime); //获得当前的UTC时间

或者GetLocalTime(&system);//

获得当前的本地时间

4. CTime与SYSTEMTIME的转换:

CTime time(CTime::GetCurrentTime());

SYSTEMTIME timeDest;

ystemTime(timeDest);

FILETIME《Windows SDk中提供的时间函数,区别于C运行库中的时间处理函数》

1. FILETIME与time_t类似,是64位整型,不过FILETIME是以100纳秒(ns)为单位

2.

使用BOOL SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime, LPFILETIME lpFileTime);以及BOOL FileTimeToSystemTime(const FILETIME* lpFileTime, LPSYSTEMTIME lpSystemTime);两函数实现互相转换。

3. 将本地FILETIME时间转换为UTC的FILETIME时间:

BOOL LocalFileTimeToFileTime(const FILETIME* lpLocalFileTime, LPFILETIME lpFileTime);

将UTC的FILETIME时间转换为本地FILETIME时间:

BOOL FileTimeToLocalFileTime(const FILETIME* lpFileTime, LPFILETIME lpLocalFileTime);

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689608049a270226.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信