forked from mouredev/Hello-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00_dates.py
75 lines (46 loc) · 1.22 KB
/
00_dates.py
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
# Clase en vídeo: https://youtu.be/TbcEqkabAWU
### Dates ###
# Date time
from datetime import timedelta
from datetime import date
from datetime import time
from datetime import datetime
now = datetime.now()
def print_date(date):
print(date.year)
print(date.month)
print(date.day)
print(date.hour)
print(date.minute)
print(date.second)
print(date.timestamp())
print_date(now)
year_2023 = datetime(2023, 1, 1)
print_date(year_2023)
# Time
current_time = time(21, 6, 0)
print(current_time.hour)
print(current_time.minute)
print(current_time.second)
# Date
current_date = date.today()
print(current_date.year)
print(current_date.month)
print(current_date.day)
current_date = date(2022, 10, 6)
print(current_date.year)
print(current_date.month)
print(current_date.day)
current_date = date(current_date.year,
current_date.month + 1, current_date.day)
print(current_date.month)
# Operaciones con fechas
diff = year_2023 - now
print(diff)
diff = year_2023.date() - current_date
print(diff)
# Timedelta
start_timedelta = timedelta(200, 100, 100, weeks=10)
end_timedelta = timedelta(300, 100, 100, weeks=13)
print(end_timedelta - start_timedelta)
print(end_timedelta + start_timedelta)