python常用时间函数
1 import time 2 import datetime 3 4 5 #函数定义 6 def getTimeNow(): 7 return datetime.datetime.now() 8 def getYesterDay(): 9 return getTimeNow() + datetime.timedelta(days=-1) 10 def getTimeByStamp(stamp): 11 temp_time = time.localtime(int(str(stamp)[0:10])) 12 str_1 = time.strftime("%Y-%m-%d %H:%M:%S", temp_time) 13 return datetime.datetime.strptime(str_1,"%Y-%m-%d %H:%M:%S")