import time import datetime YY_MM_DD_HH_MM_SS = "%Y-%m-%d %H:%M:%S" YMDHMSF = "%Y%m%d%H%M%S%f" def generate_timestamp(): """根据当前时间获取时间戳,返回整数""" return int(time.time()) def now_date_to_str(fmt=None): if fmt is None: fmt = YY_MM_DD_HH_MM_SS return datetime.datetime.now().strftime(fmt) if __name__=="__main__": print(now_date_to_str(YMDHMSF))