| 9 | from datetime import datetime |
| 10 | |
| 11 | def main(): |
| 12 | ## DATE OBJECTS |
| 13 | # Get today's date from the simple today() method from the date class |
| 14 | today = date.today() |
| 15 | print ("Today's date is ", today) |
| 16 | |
| 17 | # print out the date's individual components |
| 18 | print ("Date Components: ", today.day, today.month, today.year) |
| 19 | |
| 20 | # retrieve today's weekday (0=Monday, 6=Sunday) |
| 21 | print ("Today's Weekday #: ", today.weekday()) |
| 22 | days = ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"] |
| 23 | print ("Which is a " + days[today.weekday()]) |
| 24 | |
| 25 | ## DATETIME OBJECTS |
| 26 | # Get today's date from the datetime class |
| 27 | today = datetime.now() |
| 28 | print ("The current date and time is ", today) |
| 29 | |
| 30 | # Get the current time |
| 31 | t = datetime.time(datetime.now()) |
| 32 | print ("The current time is ", t) |
| 33 | |
| 34 | |
| 35 | if __name__ == "__main__": |