summaryrefslogtreecommitdiff
path: root/04-CustomLibrary/ExtensionPackages/GetTimeLibrary/GetTime.py
blob: 66b0cf6af13d2486fff679086f8b680f248b05a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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"