Using datetime Methods and Attributes
There are several attributes in the
datetime module that you can call on a
datetime object. If you want to see the current month, you can print your object followed by the
.month attribute, which is
The current month is October, so when you call
now.month, it returns
10, as October is the tenth month of the year. As another example, if you wanted to see just the current year, you could use the
print() function on your
now, followed by the
.year attribute, which is
For example, you can call the
.second attribute to show the current second in the current minute out of sixty, or you can call the
.weekday() method to return the day of the week as an integer, with Monday being zero and Sunday being six.
Become a Member to join the conversation.