深夜不眠,和大家分享自己刚写出来的GPS获得的UTC时间转换为北京时间,还有星期转换函数,在0.96寸oled显示
//月修正数据表
unsigned char const table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5};
//获得现在是星期几
//功能描述:输入公历日期得到星期(只允许1901-2099年)
//year,month,day:公历年月日
//返回值:星期号
unsigned char GPS_Get_Week(unsigned int year,unsigned char month,unsigned char day)
{
unsigned int temp2;
unsigned char yearH,yearL;
yearH=year/100; yearL=year%100;
// 如果为21世纪,年份数加100
if (yearH>19)yearL+=100;
// 所过闰年数只算1900年之后的
temp2=yearL+yearL/4;
temp2=temp2%7;
temp2=temp2+day+table_week[month-1];
if (yearL%4==0&&month<3)temp2--;
return(temp2%7);
}
//星期几显示
void Week_Show(unsigned int year,unsigned char month,unsigned char day)
{