#include
int get_Weekday(int Year,int Month,int Day)
{
int Weekday=0, Century=0;
if (1 == Month ) {
Month = 13;
Year = Year -1;
}
else if (2 == Month ) {
Month = 14;
Year = Year -1;
}
Century = (Year/100);
Year = Year%100;
Weekday = (Century/4) - (2*Century) + Year + (Year/4) + (13 * (Month+1) / 5) + Day - 1;
Weekday = Weekday%7;
if (Weekday < 0)
{
Weekday += 7;
}
return Weekday;
}
int main(int argc, char * argv[])
{
int year,month,weekofmonth,dayofweek,weekday;
int sumday = 0;
int leap = 0;
if (argc != 5)
{
printf("invalid pararm! year month nweek weekdays\n");
return 1;
}
year = atoi(argv[1]);
month = atoi(argv[2]);
weekofmonth = atoi(argv[3]);
dayofweek = atoi(argv[4]);
printf("year %d month %d weekofmonth %d weekdays %d\n", year, month, weekofmonth, dayofweek);
weekday = get_Weekday(year, month, 1);
printf("weekday %d\n", weekday);
if (0 == weekday)
{
sumday = (weekofmonth - 1) * 7 + dayofweek;
}
else
{
sumday = 7 - weekday + ( weekofmonth - 1) * 7 + dayofweek;
}
printf("%d/%d/%d\n", year, month, sumday);
return 0;
}
阅读(1175) | 评论(1) | 转发(0) |