-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeUtil.py
More file actions
44 lines (30 loc) · 1 KB
/
TimeUtil.py
File metadata and controls
44 lines (30 loc) · 1 KB
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
import time
import datetime
class TimeUtil:
def __init__(self) -> None:
pass
def today(self):
t = time.localtime(time.time())
return "%s-%s-%s" % (t.tm_year,t.tm_mon,t.tm_mday)
def now(self):
t = time.localtime(time.time())
return TimeObj(t.tm_year,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec)
def getTime(self):
return time.localtime(time.time())
def getYesterday(self):
today = datetime.date.today()
oneday = datetime.timedelta(days=1)
yesterday = today - oneday
return str(yesterday)
class TimeObj:
def __init__(self,year,month,day,hour,minute,second) -> None:
self.year = year
self.month = month
self.day = day
self.hour = hour
self.minute = minute
self.second = second
def toStr(self):
return "%s-%s-%s %s:%s:%s" % (self.year,self.month,self.day,self.hour,self.minute,self.second)
def __str__(self) -> str:
return self.toStr()