When we execute the code from the example above the result will be:
The date contains year, month, day, hour, minute, second, and microsecond.
The datetime
module has many methods to return information about the date object.
Here are a few examples, you will learn more about them later in this chapter:
ExampleReturn the year and name of weekday:
import datetime
x = datetime.datetime.now()
print(x.year)
print(x.strftime("%A"))
Try it Yourself ยปTrack your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4