19
19
# get day of the week using date.weekday() # Monday is 0
20
20
21
21
from datetime import date
22
- d1 = date .today ()
23
- print (d1 )
24
- print (d1 .month , d1 .day , d1 .year )
25
- print (d1 .weekday ())
22
+ todays_date = date .today ()
23
+ print (todays_date )
24
+ print (todays_date .month , todays_date .day , todays_date .year )
25
+ print (todays_date .weekday ())
26
26
27
27
# ISO format is a string format, yyyy-mm-dd
28
28
# ---------------------------
29
29
# date_object.isoformat() does the same thing as str(date_object)
30
30
31
31
from datetime import date
32
- d1 = date .fromisoformat ('2011-11-23' )
33
- print (d1 )
34
- print (str (d1 ))
35
- print (d1 .isoformat ())
36
- d1
32
+ todays_date = date .fromisoformat ('2011-11-23' )
33
+ print (todays_date )
34
+ print (str (todays_date ))
35
+ print (todays_date .isoformat ())
36
+ todays_date
37
37
38
38
# Comparison, addition and sutraction of dates
39
39
# ---------------------------
42
42
# The same comparison and add/subtract operations can be used with time objects.
43
43
44
44
from datetime import date
45
- d1 = date .today ()
45
+ todays_date = date .today ()
46
46
d2 = date (2015 , 5 , 14 )
47
- print (d1 > d2 )
48
- print (d1 - d2 )
47
+ print (todays_date > d2 )
48
+ print (todays_date - d2 )
49
49
50
50
# Time
51
51
# ---------------------------
95
95
# A timedelta can also be multiplied or divided by an integer or float
96
96
97
97
from datetime import timedelta , date , time
98
- d1 = date (2011 , 6 , 15 )
98
+ todays_date = date (2011 , 6 , 15 )
99
99
d2 = date (2012 , 9 , 18 )
100
- td = d2 - d1
100
+ td = d2 - todays_date
101
101
print (td , type (td ))
102
102
print (td .total_seconds ())
103
103
print (td * 3 )
130
130
start_time = time .process_time ()
131
131
# do some stuff
132
132
end_time = time .process_time ()
133
- print ('operation executed in ' , end_time - start_time )
133
+ print ('operation executed in ' , end_time - start_time )
0 commit comments