-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdates
32 lines (26 loc) · 879 Bytes
/
dates
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
#
# Example file for working with date information
#
from datetime import date
from datetime import time
from datetime import datetime
def main():
## DATE OBJECTS
# Get today's date from the simple today() method from the date class
today = date.today()
print("Today's date is ", today)
# print out the date's individual components
print("Date components: ", today.day, today.month, today.year)
# retrieve today's weekday (0=Monday, ="Sunday")
print("Today's weekday # is: ", today.weekday())
days = ["mon", "tue", "wed", "thur", "fri", "sat", "sun"]
print("Which is a: ", days[today.weekday()])
## DATETIME OBJECTS
# Get today's date from datetime class
today = datetime.now()
print("The current date and time is: ", today)
# Get the current time
t = datetime.time(datetime.now())
print(t)
if __name__ == "__main__":
main()