Attributes of now()
The now() has different attributes, same as attributes of time such as year, month, date, hour, minute, and second.
Example
Python3
# importing datetime module for now() import datetime # using now() to get current time current_time = datetime.datetime.now() # Printing attributes of now(). print ( "The attributes of now() are : " ) print ( "Year: " , end = "") print (current_time.year) print ( "Month: " , end = "") print (current_time.month) print ( "Day: " , end = "") print (current_time.day) |
Output:
The attributes of now() are: Year: 2019 Month: 12 Day: 11
RECOMMENDED ARTICLES – Get Current Date and Time using Python
Get current date using Python
Prerequisite: DateTime module
In Python, Date and Time are not data types of their own, but a module named DateTime can be imported to work with the date as well as time. Datetime module comes built into Python, so there is no need to install it externally. The DateTime module provides some functions to get the current date as well as time.