QT实现将两个时间相加的算法[hh: mm + hh: mm]
【1】简介【2】标志位【3】系统时间+设定的时间【源码附上】【4】系统时间+清洗时间【附上源码】【5】总结【1】简介
本次写作是在实际项目中需要,进行的时间算法,本人通过QT时间戳的方式,是无法实现两个时间相加的。但是又必须添加这个项目功能,于是自己写了一份时间算法,主要是时分的形式,例如: 12:59 + 9:59这种形式。 另外如果各位博主有更好的算法或者函数库提供,请在下方附上 link
【2】标志位
首先介绍实现的这两个函数:
void setTreatmentEndtime();
//系统时间+我设定的时间=总的需要时间
void setRinseTimeStartAndEnd(QString Val);
//将分钟转换为标准时分格式,在相加
需要设置的标志位:
//mainwindow.hprivate://======================【SJY新增】uint8_t endtime_buttonflag;//剩余时间和结束时间切换标志位 【记得在构造函数初始化=0】QString Sys_time;//记录系统时间 【只要一次,所以需要设置标志位】QString MandatoryRinse;//记录强制冲洗时间 【只要一次需要设置标志位】
【3】系统时间+设定的时间【源码附上】
请看上图,在ui设计中往往需要显示系统时间和日期,而日期不可能禁止不动,需要实时刷新,这就不得不提出QT当中的定时器
第一步创建定时器并且开启
【1】在头文件添加日期时间头
QDateTime
【2】
toString
的意思是将当前的日期时间转换为字符串,参数是时间格式,参考【QT手册assistant
】【3】在ui界面随便设置两个标签,将获取的字符串时间设置显示即可
//刷新时间【由定时器开启】 1s跑一次void MainWindow::refresh_time(){ui->label_date->setText(QDateTime::currentDateTime().toString("yyyy/MM/dd"));ui->label_time->setText(QDateTime::currentDateTime().toString("hh:mm:ss"));}
上面的函数是由定时器开启的,具体如下:
【1】在
mainwindow.h
添加定时器的头文件QTime
和对象private: QTimer timer;
【2】将定时器对象通过
connect
函数形成信号与槽,信号发送函数timeout();
槽接收函数refresh_time();
【3】&timer:对象地址【栈对象需要添加取址符&, 指针对象直接写名字,不需要&,本身就是地址】信号的发送者
【4】 timer.start(1000) :开启定时器,1s,也就是超过1s后会触发timeout()信号,start(参数是整形毫秒)
【5】timeout(): 信号发射函数,由定时器对象发射
【6】this:信号的接收者,this代码接收的是本类对象
【7】refresh_time(): 槽函数,由信号timeout触发,是本类对象的信心接收函数
//时间显示connect(&timer, SIGNAL(timeout()), this, SLOT(refresh_time()));timer.start(1000);//1s开启
第二步两个时间相加函数【已实现附上代码】
在多个MCU工作时,以下图片
第一个剩余时间:代表治疗某个病人,还需要多久
第二个结束时间:剩余结束时间+系统时间=医生几点可以下班【目的是为了直观显示】
系统时间已经在上面显示在ui了,对于label标签通过text()即可获取ui上的文本,系统时间获取;
剩余时间保存在一个数组,比如初始值=4:59
//治疗剩余时间和结束时间的切换 【SJY新增】void MainWindow::setTreatmentEndtime(){if(endtime_buttonflag == 0){bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;//QString time1_hm = data_lib->Get_Value(279);//保存在数组里QString time1_hm = ui->label_timeleft->text();//获取ui上的剩余时间QString time2_hm=ui->label_time->text();//获取ui上的系统时间m1 = time1_hm.split(":");//9:59m2 = time2_hm.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<m5<<m6<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22)//10-22{QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //hh<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //hh<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_endtime->setText(QString("%1%2:%3%4").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_26->hide();ui->label_timeleft->hide();ui->label_endtime->show();ui->label_timeend->show();endtime_buttonflag =1;}else if(endtime_buttonflag ==1){ui->label_26->show();ui->label_timeleft->show();ui->label_endtime->hide();ui->label_timeend->hide();endtime_buttonflag =0;}}
第三步实现的效果截图
系统时间
剩余时间
【1】刚开始显示的是剩余时间,默认值,可通过按钮设置
【2】在这个时间背后我添加了一个原型按钮
【3】点击原型按钮可以切换剩余时间和结束时间【方便医护人员及时及时下班】
结束时间=剩余时间+系统时间
【4】系统时间+清洗时间【附上源码】
【1】效果跟上面时一个道理,只是这里的清洗时间是分钟,范围是3-999,需要将清洗时间分钟转化为时分:hh:mm
【2】系统时间算法跟上面的一样 hh:mm
【3】想要的效果:
开始时间:hh:mm不变
结束时间=系统时间+清洗时间 hh:mm 跟随清洗时间的变化而变化
【4】清洗时间由控制MCU->发送通信给-》监控MCU->UI显示【实时变化】
第一步直接附上代码
//计算各个清洗按钮界面的开始时间和结束时间【SJY新增】void MainWindow::setRinseTimeStartAndEnd(QString Val){if(Val == "水洗"){//3-999static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();Sys_time = ui->label_time->text();//获取系统时间//qDebug()<<"Sys_time--------------------"<<Sys_time;ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));flag =1;//一直保留这个值}//QString Water_time = QString("0:%1").arg(ui->stage1_time_1->text().split(" ").at(0));//水洗时间分钟QString Water_time = QString("%1").arg(data_lib->Get_Value(71));//水洗时间分钟uint8_t hmus,min;uint32_t Total_time=Water_time.toInt();if(Total_time >59){Water_time.clear();hmus = Total_time/60;//小时min= Total_time%60;//分Water_time = QString("%1:%2").arg(hmus).arg(min);}else{Water_time.clear();Water_time = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = Water_time.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<"\n"<<m5<<m6<<"\n"<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //hh<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //hh<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else if(Val == "酸洗")//15-999{static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();Sys_time = ui->label_time->text();//获取系统时间ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));flag =1;}// QString stage1_time_3 = QString("%1").arg(ui->stage1_time_3->text().split(" ").at(0));//酸洗前水洗// QString stage2_time_3 = QString("%1").arg(ui->stage2_time_3->text().split(" ").at(0));//酸洗// QString stage3_time_3 = QString("%1").arg(ui->stage3_time_3->text().split(" ").at(0));//酸洗浸泡// QString stage4_time_3 = QString("%1").arg(ui->stage4_time_3->text().split(" ").at(0));//酸洗后水洗QString stage1_time_3 = QString("%1").arg(data_lib->Get_Value(72).split(" ").at(0));//酸洗前水洗15QString stage2_time_3 = QString("%1").arg(data_lib->Get_Value(73).split(" ").at(0));//酸洗20QString stage3_time_3 = QString("%1").arg(data_lib->Get_Value(74).split(" ").at(0));//酸洗浸泡60QString stage4_time_3 = QString("%1").arg(data_lib->Get_Value(75).split(" ").at(0));//酸洗后水洗20uint8_t hmus,min;QString stage_time;uint32_t Total_time = stage1_time_3.toInt()+stage2_time_3.toInt()+stage3_time_3.toInt()+stage4_time_3.toInt();if(Total_time >59){hmus = Total_time/60;//小时min= Total_time%60;//分stage_time = QString("%1:%2").arg(hmus).arg(min);}else{stage_time = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = stage_time.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else if(Val == "过氧乙酸清洗"){static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();Sys_time = ui->label_time->text();//获取系统时间ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));flag =1;}// QString stage1_time_2 = QString("%1").arg(ui->stage1_time_1->text().split(" ").at(0));//清洗前水洗// QString stage2_time_2 = QString("%1").arg(ui->stage2_time_2->text().split(" ").at(0));//过氧乙酸清洗// QString stage3_time_2 = QString("%1").arg(ui->stage3_time_2->text().split(" ").at(0));//过氧乙酸浸泡// QString stage4_time_2 = QString("%1").arg(ui->stage4_time_2->text().split(" ").at(0));//清洗后水洗QString stage1_time_2 = QString("%1").arg(data_lib->Get_Value(92).split(" ").at(0));//清洗前水洗QString stage2_time_2 = QString("%1").arg(data_lib->Get_Value(93).split(" ").at(0));//过氧乙酸清洗QString stage3_time_2 = QString("%1").arg(data_lib->Get_Value(94).split(" ").at(0));//过氧乙酸浸泡QString stage4_time_2 = QString("%1").arg(data_lib->Get_Value(95).split(" ").at(0));//清洗后水洗uint8_t hmus,min;QString stage_time;uint32_t Total_time = stage1_time_2.toInt()+stage2_time_2.toInt()+stage3_time_2.toInt()+stage4_time_2.toInt();if(Total_time >59){hmus = Total_time/60;//小时min= Total_time%60;//分stage_time = QString("%1:%2").arg(hmus).arg(min);}else{stage_time = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = stage_time.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<"\n"<<m5<<m6<<"\n"<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else if(Val == "消毒"){static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();Sys_time = ui->label_time->text();//获取系统时间ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));flag =1;}// QString stage1_time_4 = QString("%1").arg(ui->stage1_time_4->text().split(" ").at(0));//消毒前水洗// QString stage2_time_4 = QString("%1").arg(ui->stage2_time_4->text().split(" ").at(0));//消毒// QString stage3_time_4 = QString("%1").arg(ui->stage3_time_4->text().split(" ").at(0));//消毒静置// QString stage4_time_4 = QString("%1").arg(ui->stage4_time_4->text().split(" ").at(0));//消毒后水洗QString stage1_time_4 = QString("%1").arg(data_lib->Get_Value(77).split(" ").at(0));//消毒前水洗QString stage2_time_4 = QString("%1").arg(data_lib->Get_Value(78).split(" ").at(0));//消毒QString stage3_time_4 = QString("%1").arg(data_lib->Get_Value(79).split(" ").at(0));//消毒静置QString stage4_time_4 = QString("%1").arg(data_lib->Get_Value(80).split(" ").at(0));//消毒后水洗uint8_t hmus,min;QString stage_time;uint32_t Total_time = stage1_time_4.toInt()+stage2_time_4.toInt()+stage3_time_4.toInt()+stage4_time_4.toInt();if(Total_time >59){hmus = Total_time/60;//小时min= Total_time%60;//分stage_time = QString("%1:%2").arg(hmus).arg(min);}else{stage_time = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = stage_time.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<"\n"<<m5<<m6<<"\n"<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else if(Val == "热水冲洗"){static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();Sys_time = ui->label_time->text();//获取系统时间ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));flag =1;}// QString stage1_time_5 = QString("%1").arg(ui->stage1_time_5->text().split(" ").at(0));//热冲洗前水洗// QString stage2_time_5 = QString("%1").arg(5);//加热// QString stage3_time_5 = QString("%1").arg(ui->stage3_time_5->text().split(" ").at(0));//热水冲洗// QString stage4_time_5 = QString("%1").arg(5);//冷却// QString stage5_time_5 = QString("%1").arg(ui->stage5_time_5->text().split(" ").at(0));//热冲洗后水洗QString stage1_time_5 = QString("%1").arg(data_lib->Get_Value(83).split(" ").at(0));//热冲洗前水洗QString stage2_time_5 = QString("%1").arg(5);//加热QString stage3_time_5 = QString("%1").arg(data_lib->Get_Value(84).split(" ").at(0));//热水冲洗QString stage4_time_5 = QString("%1").arg(5);//冷却QString stage5_time_5 = QString("%1").arg(data_lib->Get_Value(85).split(" ").at(0));//热冲洗后水洗uint8_t hmus,min;QString stage_time;uint32_t Total_time = stage1_time_5.toInt()+stage2_time_5.toInt()+stage3_time_5.toInt()+stage5_time_5.toInt()+stage4_time_5.toInt();if(Total_time >59){hmus = Total_time/60;//小时min= Total_time%60;//分stage_time = QString("%1:%2").arg(hmus).arg(min);}else{stage_time = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = stage_time.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<"\n"<<m5<<m6<<"\n"<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else if(Val == "热水柠檬酸洗"){static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();Sys_time = ui->label_time->text();//获取系统时间ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));flag =1;}// QString stage1_time_6 = QString("%1").arg(ui->stage1_time_6->text().split(" ").at(0));//清洗前水洗// QString stage2_time_6 = QString("%1").arg(5);//加热// QString stage3_time_6 = QString("%1").arg(ui->stage3_time_6->text().split(" ").at(0));//热水柠檬酸洗// QString stage4_time_6 = QString("%1").arg(5);//冷却// QString stage5_time_6 = QString("%1").arg(ui->stage5_time_6->text().split(" ").at(0));//热冲洗后水洗QString stage1_time_6 = QString("%1").arg(data_lib->Get_Value(87).split(" ").at(0));//清洗前水洗QString stage2_time_6 = QString("%1").arg(5);//加热QString stage3_time_6 = QString("%1").arg(data_lib->Get_Value(88).split(" ").at(0));//热水柠檬酸洗QString stage4_time_6 = QString("%1").arg(5);//冷却QString stage5_time_6 = QString("%1").arg(data_lib->Get_Value(89).split(" ").at(0));//热冲洗后水洗uint8_t hmus,min;QString stage_time;uint32_t Total_time = stage1_time_6.toInt()+stage2_time_6.toInt()+stage3_time_6.toInt()+stage5_time_6.toInt()+stage4_time_6.toInt();if(Total_time >59){hmus = Total_time/60;//小时min= Total_time%60;//分stage_time = QString("%1:%2").arg(hmus).arg(min);}else{stage_time = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = stage_time.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<"\n"<<m5<<m6<<"\n"<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else if(Val == "强制冲洗"){static uint8_t flag =0;if(flag == 0)//第一次进入{Sys_time.clear();MandatoryRinse.clear();Sys_time = ui->label_time->text();//获取系统时间ui->label_Rinsestarttime->setText(tr(QString("开始时间 %1:%2").arg(Sys_time.split(":").at(0)).arg(Sys_time.split(":").at(1)).toUtf8().data()));MandatoryRinse = QString("0:%1").arg(ui->label_rinseleft->text().split(" ").at(0));//强制冲洗分钟flag =1;//一直保留这个值}//QString Water_time = QString("%1").arg(data_lib->Get_Value(71));//水洗时间分钟uint32_t hmus,min;uint32_t Total_time=MandatoryRinse.toInt();if(Total_time >59){MandatoryRinse.clear();hmus = Total_time/60;//小时min= Total_time%60;//分MandatoryRinse = QString("%1:%2").arg(hmus).arg(min);}else{MandatoryRinse.clear();MandatoryRinse = QString("0:%1").arg(Total_time);}bool ok;uint32_t mm,hh;QStringList m1; QStringList m2;QString m3; QString m4; QString m5; QString m6; QString h2; QString h1;m1 = MandatoryRinse.split(":");//9:59m2 = Sys_time.split(":");//例如:23:59m3 = m1.at(0);//9m4 = m1.at(1);//59m5 = m2.at(0);//23m6 = m2.at(1);//59mm =m4.toInt(&ok,10)+m6.toInt(&ok,10);//分钟hh =m3.toInt(&ok,10)+m5.toInt(&ok,10);//小时qDebug()<<m3<<m4<<"\n"<<m5<<m6<<"\n"<<hh<<mm<<endl;if((mm >=60)&&(mm <100))//分钟不能大于60 大于增加一个小时{if(mm == 60)//小时加1{m4 = QString("0");m3 = QString("0");}else//>60{//小时加1 并且拼接出分钟数值if(( mm>=61) &&(mm<=69))//01-09{m4 = QString("%1").arg(mm%60).at(0);//余数时5m3 = QString("0");}else{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);}}//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+1);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+1);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//19uint8_t ret = temp.toInt()+1;//20 //11-23h2 = QString("%1").arg(ret).at(1);if(ret >= 20){h1 = QString("%1").arg(ret).at(0);}else{h1 = QString("%1").arg(hh%24).at(0);}}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+1;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm >= 100)//大于等于100 mm最大时59+59=118{m4 = QString("%1").arg(mm%60).at(1);m3 = QString("%1").arg(mm%60).at(0);uint8_t rethh = mm/60;//转化为小时//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt()+rethh);h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt()+rethh);h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt()+rethh;h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{QString temp = QString("%1").arg(hh%24);//=9uint8_t ret = temp.toInt()+rethh;if(ret ==10)//10:00{h1 = QString("1");h2 = QString("0");}else {h1 = QString("0");h2 = QString("%1").arg(ret);}}}else if(mm<10 ){m4 = QString("%1").arg(mm%60);m3 = QString("%1").arg(0);//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}else//10<=mm>=59{m4 = QString(QString("%1").arg(mm%60).at(1));m3 = QString(QString("%1").arg(mm%60).at(0));//小时计算和求值if(hh >23)//半夜三更{h2 = QString("%1").arg(QString("%1").arg(hh%24).toInt());h1 = QString("0");}else if(hh == 23)//晚上:00.00{h1 = QString("%1").arg(QString("0").toInt());h2 = QString("0");}else if(hh>=10&&hh<=22){QString temp = QString("%1").arg(hh%24);//=10uint8_t ret = temp.toInt();h2 = QString("%1").arg(ret).at(1);h1 = QString("%1").arg(hh%24).at(0);}else //<10{uint8_t temp = QString("%1").arg(hh%24).toInt();//=9h1 = QString("0");h2 = QString("%1").arg(temp);}}ui->label_Rinseendime->setText(QString("%1%2%3:%4%5").arg("结束时间 ").arg(h1).arg(h2).arg(m3).arg(m4));//总治疗剩余时间ui->label_Rinsestarttime->show();ui->label_Rinseendime->show();}else{//扩展}}
实现的效果
【5】总结
代码实现没问题,已经调试和计算过,上面结束时间已经修改过,但是我只教方法,也作为一个记录,以后遇上直接调用即可,大家平时写代码也要养成这种习惯,我不信你什么都能记住,封装好自己的库工作压力减轻一半。
如果觉得《QT实现将两个时间相加的算法[hh: mm + hh: mm]》对你有帮助,请点赞、收藏,并留下你的观点哦!