获取时间字符串

import time
import datetime


def get_time_str():
    # 定义文件名,年月日时分秒随机数
    # fn = time.strftime('%Y%m%d%H%M%S')
    # fn = fn + '_%d' % random.randint(0, 1000)
    ct = time.time()
    local_time = time.localtime(ct)
    data_head = time.strftime("%Y%m%d%H%M%S", local_time)
    data_secs = (ct - int(ct)) * 10000
    fn = "%s%03d" % (data_head, data_secs)  # 17位时间戳
    return fn


def get_time_str1():
    """
        :return: 20220525140635467912
        :PS :并发较高时尾部随机数增加
    """
    time_str= str(datetime.datetime.fromtimestamp(time.time())).replace("-", "").replace(" ", "").replace(":","").replace(".", "") + str(random.randint(100, 999))
    return time_str

 

posted @ 2023-03-09 15:45  Wchime  阅读(57)  评论(0)    收藏  举报