| | |
| | | |
| | | |
| | | def get_time_as_millionsecond(time_str): |
| | | s_str,ms_str = time_str.split(".") |
| | | s_str, ms_str = time_str.split(".") |
| | | ts = s_str.split(":") |
| | | return int(ts[0]) * 3600 + int(ts[1]) * 60 + int(ts[2])*1000 + int(ms_str) |
| | | return int(ts[0]) * 3600 + int(ts[1]) * 60 + int(ts[2]) * 1000 + int(ms_str) |
| | | |
| | | |
| | | # 将秒数格式化为时间 |
| | |
| | | |
| | | return time_1 - time_2 |
| | | |
| | | |
| | | def trade_time_sub_with_ms(time_str_1, time_str_2): |
| | | split_time = get_time_as_second("11:30:00")*1000 |
| | | split_time = get_time_as_second("11:30:00") * 1000 |
| | | time_1 = get_time_as_millionsecond(time_str_1) |
| | | time_2 = get_time_as_millionsecond(time_str_2) |
| | | if time_1 < split_time < time_2: |
| | | time_2 = time_2 - 90 * 60*1000 |
| | | time_2 = time_2 - 90 * 60 * 1000 |
| | | elif time_2 < split_time < time_1: |
| | | time_2 = time_2 + 90 * 60*1000 |
| | | time_2 = time_2 + 90 * 60 * 1000 |
| | | |
| | | return time_1 - time_2 |
| | | |
| | | |
| | | def compare_time(time_1: str, time_2: str): |
| | | return int(time_1.replace(":", "")) - int(time_2.replace(":", "")) |
| | | |
| | | |
| | | def compare_time_with_ms(time_1: str, time_2: str): |
| | | return int(time_1.replace(":", "").replace(".", "")) - int(time_2.replace(":", "").replace(".", "")) |
| | | |
| | | |
| | | # 交易时间加几s |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(trade_time_add_millionsecond("10:36:00.123", 1000)) |
| | | print(compare_time_with_ms("10:00:00.123","10:01:01.123")) |
| | | print(trade_time_add_millionsecond("11:29:59.123", 1888)) |