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")

 

posted @ 2022-12-19 17:02  212的s  阅读(48)  评论(0编辑  收藏  举报