user-0 提问: 闲着没事，写了个根据指定时间计算星期几的函数，各位看官，看后给个评价～～

回复:
user: user-1
content: 公式真好。。

user: user-2
content: The COleDateTime class handles dates from 1 January 100 – 31 December 9999.

user: user-3
content: 用这么复杂？  int  today,week； char  day[30];          strcpy(day,"2015.09.03");         today=rstrjul(day);//since 1899.12.31,days         week=today%7;         printf("day=%s,week=%d\n",day,week);

user: user-4
content: const char *weekdays[] = {     "星期天",     "星期一",     "星期二",     "星期三",     "星期四",     "星期五",     "星期六", };  void output_weekday() {     if (total_day < 7) {         printf("%d年%d月%d日是%s\n",year,mon,day,weekdays[total_day]);     } }

user: user-0
content: 看到大家的评论，楼楼欣喜不已，以对科学尤其是数学致敬的态度重写代码，如下： #include <stdio.h> int GetWeekDay(int year,int mon,int day) { 	int weekend; 	if((1==mon) || (2==mon)) 	{ 		mon+=12; 		year-=1; 	} 	weekend=(day+2*mon+3*(mon+1)/5+year+year/4-year/100+year/400)%7; 	printf("%d\n",weekend); 	return weekend; }  int main() { 	int year=0; 	int mon=0; 	int day=0; 	while(1){ 	scanf("%d",&year); 	if(year==99)	//退出标志 		break; 	getchar(); 	scanf("%d",&mon); 	getchar(); 	scanf("%d",&day); 	getchar(); 	int week=GetWeekDay(year,mon,day); 	switch(week) 	{ 	case 0: 		printf("%d-%d-%d is  Monday\n",year,mon,day);  		break; 	case 1: 		printf("%d-%d-%d is Tuesday\n",year,mon,day); 		break; 	case 2: 		printf("%d-%d-%d is Wednesday\n",year,mon,day); 		break; 	case 3: 		printf("%d-%d-%d is Thursday\n",year,mon,day); 		break; 	case 4: 		printf("%d-%d-%d is Friday\n",year,mon,day); 		break; 	case 5: 		printf("%d-%d-%d is Saturday\n",year,mon,day); 		break; 	case 6: 		printf("%d-%d-%d is Sunday\n",year,mon,day); 		break; 	default: 		break; 	} 	} 	getchar(); 	return 0; }

user: user-0
content: @2楼@4楼 这么好的公式，很不错，很不错，多谢了

user: user-2
content: 楼主闲着没事，还是学学怎么使用COleDateTime吧。 The COleDateTime class handles dates from 1 January 100 – 31 December 9999. COleDateTime Class Members Construction  COleDateTime Constructs a COleDateTime object.  GetCurrentTime Creates a COleDateTime object that represents the current time (static member function).    Attributes  GetStatus Gets the status (validity) of this COleDateTime object.  SetStatus Sets the status (validity) of this COleDateTime object.  GetAsSystemTime Converts the time in the COleDateTime object to be represented as aSYSTEMTIME data structure.  GetYear Returns the year this COleDateTime object represents.  GetMonth Returns the month this COleDateTime object represents (1 – 12).  GetDay Returns the day this COleDateTime object represents (1 – 31).  GetHour Returns the hour this COleDateTime object represents (0 – 23).  GetMinute Returns the minute this COleDateTime object represents (0 – 59).  GetSecond Returns the second this COleDateTime object represents (0 – 59).  GetDayOfWeek Returns the day of the week this COleDateTime object represents (Sunday = 1).  GetDayOfYear Returns the day of the year this COleDateTime object represents (Jan 1 = 1).    Operations  SetDateTime Sets the value of this COleDateTime object to the specified date/time value.  SetDate Sets the value of this COleDateTime object to the specified date-only value.  SetTime Sets the value of this COleDateTime object to the specified time-only value.  Format Generates a formatted string representation of a COleDateTime object.  ParseDateTime Reads a date/time value from a string and sets the value of COleDateTime.    Operators  operator DATE Converts a ColeDateTime value into a DATE.  operator DATE* Converts a ColeDateTime value into a DATE*.  operator = Copies a COleDateTime value.  operator +, - Add and subtract ColeDateTime values.  operator +=, -= Add and subtract a ColeDateTime value from this COleDateTime object.  operator ==, <, <=, etc. Compare two ColeDateTime values.    Data Members  m_dt Contains the underlying DATE for this COleDateTime object.  m_status Contains the status of this COleDateTime object.    Archive/Dump  operator << Outputs a COleDateTime value to Carchive or CDumpContext.  operator >> Inputs a ColeDateTime object from CArchive.    COleDateTime Overview |  Hierarchy Chart COleDateTime::GetDayOfWeek int GetDayOfWeek( ) const;  Return Value  The day of the week represented by the value of this COleDateTime object.  Remarks  Call this member function to get the day of the week represented by this date/time value.  Valid return values range between 1 and 7, where 1=Sunday, 2=Monday, and so on. If the status of this COleDateTime object is not valid, the return value is AFX_OLE_DATETIME_ERROR.  For information on other member functions that query the value of this COleDateTime object, see the following member functions:   GetDay   GetMonth   GetYear   GetHour   GetMinute   GetSecond   GetDayOfYear  COleDateTime Overview |  Class Members |  Hierarchy Chart  See Also   COleDateTime::COleDateTime, COleDateTime::SetDateTime, COleDateTime::operator =, COleDateTime::GetStatus

user: user-5
content: /****************************************************************************/ /* Function Name    :    getWeekdayFromGrogoryDate                          */ /* Description      :    通过格里高利日期获取星期                               */ /*--------------------------------------------------------------------------*/ /* Parameter        :    1) year        :    年(阳历)                        */ /*                       2) month       :    月(阳历)                        */ /*                       3) day         :    日(阳历)                        */ /*--------------------------------------------------------------------------*/ /* Return            :    星期几(0~6)[0为星期天,1~6 为星期一至星期六]            */ /* Remark            :    使用 基姆拉尔森计算公式                               */ /*                        W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1) mod 7   */ /*                        把1月和2月看成是上一年的13月和14月                     */ /****************************************************************************/ int getWeekdayFromGrogoryDate(int year, int month, int day) {     if ((1 == month) || (2 == month))     {         month += 12;    /* 13/14月 */         year -= 1;        /* 上一年 */     }          return (day + 2 * month + 3 * (month + 1)/5 + year + year/4 - year/100 + year/400 + 1) % 7; }

user: user-6
content: 其实是有公式可计算的。 S=x-1+[(x-1)/4]-[(x-1)/100]+[(x-1)/400]+t  其中x表示公元的年号，中括号内的分数计算时，只取商的整数部分即可。 t表示从这一年的元旦开始算到要求的这一天为止的天数

user: user-7
content: 没有用到这个方面的，看着很复杂，楼主辛苦了。