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)
本文为原创文章,转载请标明出处