Get the current date using datetime.now()
Python library defines a function that can be primarily used to get the current time and datetime.now() function and return the current local date and time, which is defined under the DateTime module.
Syntax: datetime.now(tz)
Parameters : tz : Specified time zone of which current time and date is required. (Uses Greenwich Meridian time by default.) Returns : Returns the current date and time in time format.
Example:
Python3
# Import datetime class from datetime module from datetime import datetime # returns current date and time now = datetime.now() print ( "now = " , now) |
Output:
now = 2019-12-11 10:58:37.039404
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.