1 当前时间字符串

# -*- coding: utf-8 -*-

import time

if __name__ == '__main__':
    # 以年_月_日_时_分_秒形式输出时间字符串,示例为2022_07_21_11_26_01
    current_time_str = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime(time.time()))
    print(current_time_str)

输出

2022_07_21_11_26_30