# 得到当前时间 2018-12-04 13:00:00
def GetTimeHour():
t= time.strftime('%Y-%m-%d %H', time.localtime(time.time()))
return datetime.datetime.strptime(t, "%Y-%m-%d %H")
# 当前时间加指定小时
def GetTimeHour_Add(hour):
t = time.strftime('%Y-%m-%d %H', time.localtime(time.time()))
t_h= datetime.datetime.strptime(t, "%Y-%m-%d %H")
t_h += datetime.timedelta(hours=hour)
return t_h
# 得到当前时间 2018-12-04 13:55:06
def GetTimeNow():
t= time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
return datetime.datetime.strptime(t, "%Y-%m-%d %H:%M:%S")
# 得到当前天 2018-12-04 0:00:00
def GetTimeDay():
t= time.strftime('%Y-%m-%d ', time.localtime(time.time()))
return datetime.datetime.strptime(t, "%Y-%m-%d ")
# 得到当前时间秒
secondtt = time.strftime('%S', time.localtime(time.time()))
#得到当前时间小时
hourtt = time.strftime('%H', time.localtime(time.time()))
import time,datetime
# 根据日期返回星期几
def get_week_day(date):
week_day_dict = {
0 : '星期一',
1 : '星期二',
2 : '星期三',
3 : '星期四',
4 : '星期五',
5 : '星期六',
6 : '星期天',
}
day = date.weekday()
return week_day_dict[day]
print(get_week_day(datetime.datetime.now()))
网友评论