Python TutorialLesson 27Free preview
Python Dates
This lesson is part of Python · All levels
Summary
The datetime module provides a class to work with dates, times, durations, and time zones in Python. We can take the current time with datetime.now(), build a specific date, even calculate the difference between the two dates into a timedelta object. The format results are often displayed in standard form such as ISO 8601 to be consistent.
Key points
- The class datetime, date, and time each represent a different part of time.
- Datetime.now() returns the current date and time.
- The timedelta represents the difference or duration between two time periods.
- Strftime() transforms time objects into strings with a specific format.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.