这个计时器应该是最准的
运用系统时间改变判断时间
新增了关机系统,重启,但重启不可用,因该是win11的问题
上代码
#include<windows.h>
#include<bits/stdc++.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
bool tomc=false;int jishirenwu;
int of_time;int p;int ffpti_h;int ffpti_m;int ffpti_s;int ff1;int ff2; int ff3;
bool timecout(){time_t timep;struct tm *tp;time(&timep);tp=localtime(&timep); p=tp->tm_sec;
if(of_time!=p){of_time=p;return false;}else{return true;}}
int timetoc(bool a){
if(ffpti_h==0&&ffpti_m==0&&ffpti_s==0){
system("cls");
Sleep(250);
system("color 04");
cout<<"-------------剩余时间-------------"<<endl<<endl;
cout<<" "<<"0"<<":"<<"0"<<":"<<"0"<<endl<<endl;
cout<<"----------------------------------"<<endl<<endl;
cout<<"---------------状态---------------" <<endl;
cout<<"计时时间:"<<ff1<<":"<<ff2<<":"<<ff3<<endl;
cout<<"计时完成!!!"<<endl<<endl;
cout<<"---------------调试---------------"<<endl;
cout<<"TIME"<<"("<<"?"<<")";
cout<<"记时后任务:";if(jishirenwu==1){
cout<<"关机";system("shutdown -s -t 3");MessageBox(NULL,"电脑将于3秒后关机","提示",MB_OK);}else if(jishirenwu==2){cout<<"重启";system("shutdown -i -r 00");}else cout<<"无";
Sleep(250);
}
else{
if(tomc==false){
if(a==false)ffpti_s--;
if(ffpti_h>0&&ffpti_m==0&&ffpti_s==0){
ffpti_h--;ffpti_m=59;ffpti_s=59;}
else{
if(ffpti_m<=0&&ffpti_h>0){ffpti_h--;ffpti_m=59;}
if(ffpti_s<=0&&ffpti_m>0){ffpti_m--;ffpti_s=59;}
}
cout<<"-------------剩余时间-------------"<<endl<<endl;
cout<<" "<<ffpti_h<<":"<<ffpti_m<<":"<<ffpti_s<<endl<<endl;
cout<<"----------鼠标中键暂停/开始-------"<<endl<<endl;
cout<<"---------------状态---------------" <<endl;
cout<<"计时时间:"<<ff1<<":"<<ff2<<":"<<ff3<<endl;
cout<<"正在计时..."<<endl<<endl;
cout<<"---------------调试---------------"<<endl;
cout<<"TIME"<<"("<<p<<")";
cout<<"记时后任务:";if(jishirenwu==1)cout<<"关机";else if(jishirenwu==2)cout<<"重启";else cout<<"无";
system("cls");
if(KEY_DOWN(VK_MBUTTON)){
tomc=true;
system("mode con cols=34 lines=21");
system("color 04");
}
}
else{
cout<<"-------------剩余时间-------------"<<endl<<endl;
cout<<" "<<ffpti_h<<":"<<ffpti_m<<":"<<ffpti_s<<endl<<endl;
cout<<"----------鼠标中键键暂停/开始-------"<<endl<<endl;
cout<<"---------------状态---------------" <<endl;
cout<<"计时时间:"<<ff1<<":"<<ff2<<":"<<ff3<<endl;
cout<<"正在暂停..."<<endl<<endl;
cout<<"---------------调试---------------"<<endl;
cout<<"TIME"<<"("<<p<<")"<<endl;
cout<<"记时后任务:";if(jishirenwu==1)cout<<"关机";else if(jishirenwu==2)cout<<"重启(错误)";else cout<<"无";
system("cls");
if(KEY_DOWN(VK_MBUTTON)){
tomc=false;
system("mode con cols=34 lines=21");
system("color 02");
}
}
}
}
int main(){
system("mode con cols=34 lines=21");
cout<<"小时: <<分钟: 秒:";cin>>ffpti_h;system("cls");cout<<"小时:"<<ffpti_h<<" 分钟: << 秒:";cin>>ffpti_m;
system("cls");cout<<"小时:"<<ffpti_h<<"分钟:"<<ffpti_m<<" 秒:<<";cin>>ffpti_s;system("cls");
ff1=ffpti_h;ff2=ffpti_m;ff3=ffpti_s;ffpti_s++;
cout<<"记时完成后任务(0跳过)1.关机 2.重启";cin>>jishirenwu;
system("mode con cols=34 lines=21");
system("color 02");
while(1){timetoc(timecout());}
return 0;
}
可能会出现闪屏现象,建议使用win10 win11