.datetime.now() method returns a new
datetime object with the current local date and timestamp.
The result from the
.datetime.now() method contains the year, month, day, hour, minute, second, and microsecond (expressed as
It also accepts an optional
time_zone parameter, which is set to
None by default.
The current date and time can be retrieved and stored in a variable as shown below:
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn Python on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification