Python时间使用

##### python  datetime使用

# 秒级时间戳
def log_last_one_time(minutes=60):
    time = (datetime.datetime.now()-datetime.timedelta(minutes=minutes)).strftime("%Y-%m-%d %H")
    print(time)
    dt = datetime.datetime.strptime(time, '%Y-%m-%d %H')
    return datetime.datetime.timestamp(dt)


# 秒级时间戳
def log_current_time():
    time = datetime.datetime.now().strftime("%Y-%m-%d %H")
    print(time)
    dt = datetime.datetime.strptime(time, '%Y-%m-%d %H')
    return datetime.datetime.timestamp(dt)


def str_to_timestamp(s):
    dt = datetime.datetime.strptime(s,  '%Y-%m-%d %H:%M:%S')
    return datetime.datetime.timestamp(dt)

 

posted @ 2021-11-21 17:36  亚洲哈登  阅读(41)  评论(0编辑  收藏  举报