📄 time.c
字号:
/*========================================================================
*
* 版权所有 (C) 2000-2001 吴柏建. All Rights Reserved.
*
* 文件: time.c
* 内容: PSDE_DEMO_ED处理时间的函数。
* 作者: 吴柏建。
* 制作日期: 2000.8.6-2001.8.6
* 修改日期: 2001..
*
*========================================================================*/
#include "pda.h"
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---得到每月的最大天数-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
int GetMonthMaxDay(int year,int month)
{
switch(month)
{
case 4:
case 6:
case 9:
case 11:return 30;
case 2:if((year%4!=0)||(year%100==0&&year%400!=0))return 28;else return 29;
default:return 31;
}
}
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---得到某一天的星期数-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
int GetWeek(int year,int month,int day)
{
long i;
i=1461*(long)(month<=2?year-1:year)/4+153*(long)(month<=2?month+13:month+1)/5+day;
return (int)((i-621049)%7);
}
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---时间增加一小时-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
void TimeHourAdd(PDATIME *time)
{
if(++time->hour>23)
{
time->hour=0;
if(++time->day>GetMonthMaxDay(time->year,time->month))
{
time->day=1;
if( ++time->month>12 )
{
time->month=1;
if(++time->year>2099)time->year=2099;
}
}
}
}
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---时间减少一小时-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
void TimeHourDec(PDATIME *time)
{
if(--time->hour<0)
{
time->hour=23;
if(--time->day<=0)
{
if( --time->month<0 )
{
time->month=12;
if(--time->year<1900)time->year=1900;
}
time->day=GetMonthMaxDay(time->year,time->month);
}
}
}
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---时间处理小时改变-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
void TimeHourChange(int hour,PDATIME *time)
{
if(hour>0){while(hour--)TimeHourAdd(time);}
else if(hour<0)while(hour++)TimeHourDec(time);
}
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---处理time结构增加一分钟的函数-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
void TimeMinuteAdd(PDATIME *time)
{
static int i;
if(++time->minute>59)
{
time->minute=0;
if(++time->hour>23)
{
time->hour=0;
switch(time->month)
{
case 4:
case 6:
case 9:
case 11:i=30;break;
case 2:if((time->year%4!=0)||(time->year%100==0&&time->year%400!=0))i=28;else i=29;break;
default:i=31;break;
}
if(++time->day>i)
{
time->day=1;
if( ++time->month>12 )
{
time->month=1;
if(++time->year>2099)time->year=2099;
}
}
}
}
}
/*≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
□---处理time结构增加一秒的函数-------
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡*/
void TimeSecondAdd(PDATIME *time)
{
if(++time->second>59 )
{
time->second=0;
TimeMinuteAdd(time);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -