当前位置:网站首页>解锁时间生成与比较

解锁时间生成与比较

2022-08-09 22:50:00 硬件狗

Date_Unlock_Gen()

说明:假代码,用于生成解锁的时间节点。

unsigned int Date_Unlock_Comp()

说明:假代码,比较当前时间是否超过生成的时间节点,并返回是否进行解锁。

Date_Unlock_Gen()

{
//Define Lock_Minute
unsigned int Lock_Minute; //Max=255/3*15/60=21.25Hour
//Get Date_Now
unsigned int Year_Now=2022;
unsigned int Month_Now=8;
unsigned int Day_Now=9;
unsigned int Hour_Now=10;
unsigned int Minute_Now=42;
//Define Date_Unlock
unsigned int Year_Unlock;
unsigned int Month_Unlock;
unsigned int Day_Unlock;
unsigned int Hour_Unlock;
unsigned int Minute_Unlock;

static unsigned int Hour1_Unlock;
static unsigned int Day1_Unlock;

//Initiate date unlocked
Month_Unlock=Month_Now;
Day_Unlock=Day_Now;
Hour_Unlock=Hour_Now;
Minute_Unlock=Minute_Now;

Minute_Unlock=(Minute_Now+Lock_Minute)%60;
Hour1_Unlock=Hour_Now+(Minute_Now+Lock_Minute)/60;
Hour_Unlock=Hour1_Unlock%24;
Day1_Unlock=Day_Now+Hour1_Unlock/24;

if(Day1_Unlock>31&&(Month_Now==1||Month_Now==3||Month_Now==5||Month_Now==7||Month_Now==8||Month_Now==10||Month_Now==12))
{
    Day_Unlock=Day1_Unlock%31;
    Month_Unlock=Month_Now+Day1_Unlock/31;
    if(Month_Unlock>12)
    {
        Month_Unlock=Month_Unlock%12;
        Year_Unlock=Year_Now+Month_Unlock/12;
    }
}

if(Day1_Unlock>30&&(Month_Now==4||Month_Now==6||Month_Now==9||Month_Now==11))
{
    Day_Unlock=Day1_Unlock%30;
    Month_Unlock=Month_Now+Day1_Unlock/30;
}

if(Day1_Unlock>28&&(Month_Now==2))
{
    if(Year_Now%4==0)
    {
    Day_Unlock=Day1_Unlock%29;
    Month_Unlock=Month_Now+Day1_Unlock/29;
    }
    else
    {
    Day_Unlock=Day1_Unlock%28;
    Month_Unlock=Month_Now+Day1_Unlock/28;
    }  
}

}


unsigned int Date_Unlock_Comp()
{
unsigned int Unlock=0;
unsigned int Lock=1;
//Get Date_Now and Date_Unlock
unsigned int Year_Now=2022;
unsigned int Month_Now=8;
unsigned int Day_Now=9;
unsigned int Hour_Now=10;
unsigned int Minute_Now=42;

unsigned int Year_Unlock=2022;
unsigned int Month_Unlock=8;
unsigned int Day_Unlock=8;
unsigned int Hour_Unlock=8;
unsigned int Minute_Unlock=8;

//Compare
if(Year_Now>Year_Unlock)
return Unlock;
else
if(Month_Now>Month_Unlock)
return Unlock;
else
if(Day_Now>Day_Unlock)
return Unlock;
if(Hour_Now>Hour_Unlock)
return Unlock;
if(Minute_Now>Minute_Unlock)
return Unlock;
else
return Lock;

}
原网站

版权声明
本文为[硬件狗]所创,转载请带上原文链接,感谢
https://blog.csdn.net/alexander122436/article/details/126243676