且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

给定日期,获取星期几 - SYSTEMTIME

更新时间:2022-10-18 09:11:16

如果SYSTEMTIME无法做到这一点,根据 msdn 当将 SYSTEMTIME 转换为 FILETIME 时,将忽略wDayOfWeek 成员。

  SYSTEMTIME t = {2010,6,-1 / * ignored * /,11} ; 
FILETIME ft;
HRESULT hrto = SystemTimeToFileTime(& t,& ft);
HRESULT hrback = FileTimeToSystemTime(& ft,& t);

WORD dayofweek = t.wDayOfWeek;


Is it possible to determine the day of the week, using SYSTEMTIME, if a date (month-day-year) is provided or is this structure one-way only?

What is the most lightweight way to accomplish what I am asking if SYSTEMTIME cannot do it (using Win32)?

According to the msdn, the wDayOfWeek member is ignored when converting SYSTEMTIME to FILETIME. When converting back, it's filled in.

SYSTEMTIME t = { 2010, 6, -1 /*ignored*/, 11 };
FILETIME ft;
HRESULT hrto   = SystemTimeToFileTime( &t, &ft );
HRESULT hrback = FileTimeToSystemTime( &ft, &t );

WORD dayofweek = t.wDayOfWeek;