| | |
| | | #include <iostream> |
| | | #include <ctime> |
| | | #include <string> |
| | | #include <sstream> |
| | | #include <vector> |
| | | |
| | | class TimeUtil { |
| | | public: |
| | |
| | | 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; |
| | | } |
| | | |
| | | }; |