python常用日期时间操作方法

13位时间戳

import time
timestamp = int(round(time.time() * 1000))

#10位unix时间戳
timestmp=int(time.time())

格式化日期

time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

datetime

import datetime

datetime.datetime.now().__format__("%Y-%m-%d %H:%M:%S")  #格式化日期时间
datetime.datetime.utcnow()

datetime转换为unix时间戳

ans_time = time.mktime(datetime.datetime.now().timetuple())

将unix时间戳转换为python的datetime

time = datetime.datetime.fromtimestamp(1439111214)