开发者

Given Date, Get Day of Week - SYSTEMTIME

开发者 https://www.devze.com 2023-01-03 05:31 出处:网络
Is it possible to determine the day of the week, using SYSTEMTIME, if a da开发者_StackOverflow社区te (month-day-year) is provided or is this structure one-way only?

Is it possible to determine the day of the week, using SYSTEMTIME, if a da开发者_StackOverflow社区te (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;


Another way of doing it that might be a bit more platform independent would be to use localtime or gmtime.

For example, print current day of week:

struct tm *timeval;
time_t tt;
tt = time( NULL );
timeval = localtime( &tt );
// print zero based day of week
printf( "day of week = %d\n", timeval->tm_wday );


Use SystemTimeToFileTime to covert the SYSTEMTIME to a FILETIME. Then use FileTimeToSystemTimeto convert it to a SYSTEMTIME with day of week.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号