86 lines
3.2 KiB
Python
86 lines
3.2 KiB
Python
#coding=utf-8
|
|
import datetime
|
|
import time
|
|
import string
|
|
class GetTime():
|
|
def __init__(self):
|
|
pass
|
|
def time1(self,t):
|
|
if t=="m":
|
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
|
|
if time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[-4] >= "5":
|
|
time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-4]+"5:00"
|
|
return time2
|
|
else:
|
|
time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-4] + "0:00"
|
|
return time2
|
|
elif t=="s":
|
|
if time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[-2] >= "3":
|
|
time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-2]+"30"
|
|
return time2
|
|
else:
|
|
time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-2] + "00"
|
|
return time2
|
|
elif t=="h":
|
|
time2=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[0:-7]+":00:00"
|
|
startTime = datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S")
|
|
startTime2 = (startTime + datetime.timedelta(hours=-1)).strftime("%Y-%m-%d %H:%M:%S")
|
|
return startTime2
|
|
elif t=="5m":
|
|
time2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
|
|
print(time2)
|
|
startTime = datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S")
|
|
startTime2 = (startTime + datetime.timedelta(minutes=-5)).strftime("%Y-%m-%d %H:%M:%S")
|
|
if startTime2[-4]>="5":
|
|
time3 = startTime2[0:-4] + "5:00"
|
|
print(time3)
|
|
else:
|
|
time3 = startTime2[0:-4] + "0:00"
|
|
print(time3)
|
|
return time3
|
|
elif t== "30s":
|
|
time2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
|
|
print(time2)
|
|
startTime = datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S")
|
|
startTime2 = (startTime + datetime.timedelta(seconds=-30)).strftime("%Y-%m-%d %H:%M:%S")
|
|
if startTime2[-2] >= "3":
|
|
time3 = startTime2[0:-2]+"30"
|
|
print(time3)
|
|
return time3
|
|
else:
|
|
time3 = startTime2[0:-2]+"00"
|
|
print(time3)
|
|
return time3
|
|
def str2sec(self,x):
|
|
a, b = x.strip().split(' ')
|
|
y, m, d = a.strip().split('-')
|
|
|
|
h, m, s = b.strip().split(':') #.split()函数将其通过':'分隔开,.strip()函数用来除去空格
|
|
|
|
return int(h)*3600 + int(m)*60 + int(s),d #int()函数转换成整数运算
|
|
def intersection(self,a,b):
|
|
c= 0
|
|
f = 0
|
|
for j in a:
|
|
|
|
for i in j:
|
|
if i in b[f]:
|
|
print(i)
|
|
print(b[f])
|
|
c= c+1
|
|
f = f + 1
|
|
d = len(b)*len(b[0])
|
|
if d == 0:
|
|
e=0
|
|
elif c==0:
|
|
e = 0
|
|
else:
|
|
e = c/d
|
|
if e >= 0.8 :
|
|
return "ture"
|
|
else:
|
|
return "false"
|
|
|
|
|
|
|