-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Human Readable Date.py
More file actions
62 lines (57 loc) · 1.93 KB
/
Python Human Readable Date.py
File metadata and controls
62 lines (57 loc) · 1.93 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from datetime import datetime
# Inspired By Blurbs Framework - Human Readable Date
# Rubi Jihantoro - jihantoro8@gmail.com
now = datetime.today()
date = datetime(2017, 2, 24, 23, 36, 1) #your date
# Language
second = ' Second Ago'
minute = ' Minute Ago'
hours = ' Hours Ago'
ytd = 'Yesterday, At '
on = ' On '
dnow = [
now.strftime('%Y'),
now.strftime('%m'),
now.strftime('%d'),
now.strftime('%H'),
now.strftime('%M'),
now.strftime('%S'),
now.strftime('%p')
]
myd = [
date.strftime('%Y'),
date.strftime('%m'),
date.strftime('%d'),
date.strftime('%H'),
date.strftime('%M'),
date.strftime('%S'),
date.strftime('%p'),
date.strftime('%b')
]
dpo = int(myd[2])+1
def read():
if dnow[0]+dnow[1]+dnow[2]+dnow[3]+dnow[4] == myd[0]+myd[1]+myd[2]+myd[3]+myd[4]:
ns = int(dnow[5])
ms = int(myd[5])
nr = ns-ms
x = repr(nr) + second
print(x)
elif dnow[0]+dnow[1]+dnow[2]+dnow[3] == myd[0]+myd[1]+myd[2]+myd[3]:
ns = int(dnow[4])
ms = int(myd[4])
nr = ns-ms
x = repr(nr) + minute
print(x)
elif dnow[0]+dnow[1]+dnow[2] == myd[0]+myd[1]+myd[2]:
ns = int(dnow[3])
ms = int(myd[3])
nr = ns-ms
x = repr(nr) + hours
print(x)
elif dnow[0]+dnow[1]+dnow[2] == myd[0]+myd[1]+str(dpo):
x = ytd + myd[3] + ':' + myd[4] + myd[6]
print(x)
elif dnow[0]+dnow[1]+dnow[2] > myd[0]+myd[1]+str(dpo):
x = myd[2] + ' ' + myd[7] + ' ' + myd[0] + on + myd[3] + ':' + myd[4] + myd[6]
print(x)
read()