我想从 COleDateTime 对象中获取年份和月份,并且希望它尽可能快。我有两个选择;
COleDateTime my_date_time;
int year = my_date_time.GetYear();
int month = my_date_time.GetMonth();
或者
COleDateTime my_date_time;
SYSTEMTIME mydt_as_systemtime;
my_date_time.GetAsSystemTime(mydt_as_systemtime);
int year = mydt_as_systemtime.wYear;
int month = mydt_as_systemtime.wMonth;
问题是,哪个更快?
COleDateTime将其内部日期表示存储为DATEtypedef,因此当您调用时GetYear(),GetMonth()它必须每次都计算这些。在这种SYSTEMTIME情况下,wYearand的值wMonth存储为DWORDs ,因此这只是检索值的一种情况,但是将 a 转换COleDateTime为 a会产生开销SYSTEMTIME。
谢谢,
斯特伦