.datetime.now()
Published Jun 7, 2022
Contribute to Docs
The .datetime.now()
method returns a new datetime
object with the current local date and timestamp.
Syntax
datetime.datetime.now(time_zone=None)
The result from the .datetime.now()
method contains the year, month, day, hour, minute, second, and microsecond (expressed as YYYY-MM-DD hh:mm:ss.ffffff
).
It also accepts an optional time_zone
parameter, which is set to None
by default.
Codebyte Example
The current date and time can be retrieved and stored in a variable as shown below:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.