Skip to content

Commit cdb40bd

Browse files
committed
JS - datetimes code
1 parent 1ce0f22 commit cdb40bd

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!python3
2+
3+
from datetime import datetime
4+
from datetime import date
5+
6+
datetime.today()
7+
#datetime.datetime(2018, 2, 19, 14, 38, 52, 133483)
8+
9+
today = datetime.today()
10+
11+
12+
type(today)
13+
#<class 'datetime.datetime'>
14+
15+
16+
todaydate = date.today()
17+
18+
todaydate
19+
#datetime.date(2018, 2, 19)
20+
21+
type(todaydate)
22+
#<class 'datetime.date'>
23+
24+
todaydate.month
25+
#2
26+
27+
todaydate.year
28+
#2018
29+
30+
todaydate.day
31+
#19
32+
33+
34+
christmas = date(2018, 12, 25)
35+
christmas
36+
#datetime.date(2018, 12, 25)
37+
38+
if christmas is not todaydate:
39+
print("Sorry there are still " + str((christmas - todaydate).days) + " until Christmas!")
40+
else:
41+
print("Yay it's Christmas!")
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!python3
2+
3+
from datetime import datetime
4+
from datetime import timedelta
5+
6+
t = timedelta(days=4, hours=10)
7+
8+
t.days
9+
#4
10+
11+
t.seconds
12+
#36000
13+
14+
t.hours
15+
#Traceback (most recent call last):
16+
#File "<pyshell#119>", line 1, in <module> t.hours
17+
#AttributeError: 'datetime.timedelta' object has no attribute 'hours'
18+
19+
t.seconds / 60 / 60
20+
#10.0
21+
22+
t.seconds / 3600
23+
#10.0
24+
25+
26+
#########
27+
28+
eta = timedelta(hours=6)
29+
30+
today = datetime.today()
31+
32+
today
33+
#datetime.datetime(2018, 2, 19, 14, 55, 19, 197404
34+
35+
today + eta
36+
#datetime.datetime(2018, 2, 19, 20, 55, 19, 197404)
37+
38+
str(today + eta)
39+
#'2018-02-19 20:55:19.197404'

0 commit comments

Comments
 (0)