简体   繁体   English

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

[英]Given Date, Get Day of Week - SYSTEMTIME

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? 是否可以使用SYSTEMTIME确定星期几,如果提供了日期(月日年),或者此结构仅是单向的?

What is the most lightweight way to accomplish what I am asking if SYSTEMTIME cannot do it (using Win32)? 什么是完成我要问SYSTEMTIME无法做到的最轻巧的方法(使用Win32)?

According to the msdn , the wDayOfWeek member is ignored when converting SYSTEMTIME to FILETIME . 根据msdn ,将SYSTEMTIME转换为FILETIME时将忽略wDayOfWeek成员。 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 . 另一种可能与平台无关的方式是使用localtimegmtime

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. 使用SystemTimeToFileTime将SYSTEMTIME转换为FILETIME。 Then use FileTimeToSystemTimeto convert it to a SYSTEMTIME with day of week. 然后使用FileTimeToSystemTime将其转换为带有星期几的SYSTEMTIME。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM