What are the commonly used methods in the datetime module in Python?
Commonly used methods in the datetime module in Python include:
- Returns the current date and time.
- Create a datetime object with the specified date and time using datetime.datetime(year, month, day, hour, minute, second).
- Convert a string to a datetime object by specifying the format of the string, using datetime.datetime.strptime(date_string, format).
- The datetime object is converted to a string in the specified format using the datetime.datetime.strftime(format) method.
- datetime.datetime.date(): returns the date part of the datetime object.
- time() returns the time part of a datetime object.
- datetime.datetime.timestamp(): Returns the timestamp of a datetime object.
- Replace specific parts of a datetime object with the given year, month, day, hour, minute, and second.
- The datetime.timedelta(days, seconds, microseconds) represents a duration of time that can be used for adding or subtracting dates and times.
- datetime.timedelta.total_seconds(): Returns the total number of seconds in the time interval.