C++ 计算两个时间差

#include <iostream>

#include <stdio.h>

using namespace std;

int CalculateTime(string timeBegin,sting timeEnd)

{

        int hour1,minute1;

       int hour2,minute2;

       int hour,minute;

      sscanf(timeBegin.c_str(),”%d:%d”,&hour1,&minute1);
      sscanf(timeEnd.c_str(),”%d:%d”,&hour2,&minute2);

      if(minute2 < minute1)
     {
         minute = minute2 + 60 – minute1;
         hour2–;
     } else
     {
         minute = minute2 – minute1;
     }
     if (hour2 < hour1)
     {
         hour = hour2 + 24 – hour1;
     }else
     {
         hour = hour2 – hour1;
     }

    return hour
}

int main()

{

      string time1 = “08:00”;

      string time2 = “12:00”;

      int hour = CalculateTime(time1,time2);

     cout<<hour<<endl;

}

    原文作者:my_angle2016
    原文地址: https://blog.csdn.net/my_angle2016/article/details/114887300
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞