admin
2024-05-17 56092db23f41123e2d24c7a1d79608d663297733
common/TimeUtil.h
@@ -2,6 +2,8 @@
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include <vector>
class TimeUtil {
public:
@@ -56,4 +58,34 @@
        return timestamp;
    }
    // 时间相减,返回相差的s
    static int trade_time_sub(string time_str_1, string time_str_2) {
        int time_1[3], time_2[3];
        // 切割时间
        std::string token;
        std::vector<std::string> results = StringUtil::split(time_str_1,":");
        int index = 0;
        for (std::vector<std::string>::iterator e = results.begin(); e != results.end(); e++) {
            time_1[index] = stoi(*e);
            index++;
        }
        results = StringUtil::split(time_str_2, ":");
        index = 0;
        for (std::vector<std::string>::iterator e = results.begin(); e != results.end(); e++) {
            time_2[index] = stoi(*e);
            index++;
        }
        int split_time = 11 * 3600 + 30 * 60 + 0;
        int time_1_int = time_1[0] * 3600 + time_1[1] * 60 + time_1[2];
        int time_2_int = time_2[0] * 3600 + time_2[1] * 60 + time_2[2];
        if (split_time > time_1_int && split_time < time_2_int) {
            time_2_int = time_2_int - 90 * 60;
        }
        else if (split_time > time_2_int && split_time < time_1_int) {
            time_2_int = time_2_int + 90 * 60;
        }
        return time_1_int - time_2_int;
    }
};