星期几到星期几怎么算,星期几是怎么算出来的

首页 > 日历 > 作者:YD1662023-04-14 15:36:17

时间日历结构体

typedef struct tagClock

{
UINT8 minute; //分钟
UINT8 hour; // 小时
UINT8 day; //天
UINT8 month; //月
UINT8 year; //年
UINT8 week; //星期
UINT8 dst_flag; //ST,DST标志
UINT8 second; //秒

}CLOCK;


// 星期修正表
static const UINT8 WEEKDAY_KEYNO[15] = { // all add 7-2 ,to prevent 2000-1-1 calc week result is error
0, // 0, /* dummy*/
6, // 1, /* January */
9, // 4, /* February */
9, // 4, /* March */
5, // 0, /* April */
7, // 2, /* May */
10, // 5, /* June */
5, // 0, /* July */
8, // 3, /* August */
11, // 6, /* September */
6, // 1, /* October */
9, // 4, /* November */
11, // 6, /* December */
5, // 0, /* leap January */
8 // 3, /* leap February */
};
/**********************************************************************************************************
Routine Name: cal_weekday
Form: void cal_weekday(CLOCK* self)
Parameters: CLOCK* self
self----point to CLOCK struct first address
Return Value: void
Description: calc week ------calc range is 00yr- 1-1 ~ 99 yr 12-31,2000年基数被省略
***********************************************************************************************************/
void cal_weekday(CLOCK* self)
{
CLOCK *ptr = self;
UINT8 rm_week_i;
rm_week_i= WEEKDAY_KEYNO[ptr->month]; //查星期修正表
if((ptr->month<3)&&((ptr->year & 0x03)==0)) //润年的1,2月处理
{
rm_week_i--;
}
// so modify it to (last 2 yr digit 1/4(last 2 yr digit) days keyno ) mod 7
// the remainder is the result: 0=sunday, 1=monday, 2=Tue ....
ptr->week=((rm_week_i ptr->day ptr->year (ptr->year>>2))%7);
}

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.