📅  最后修改于: 2023-12-03 15:20:33.741000             🧑  作者: Mango
Temps 3 is a powerful tool for managing time and dates in Python programs. This library provides several classes and functions to manipulate dates and times, including:
Temps 3 provides several objects for representing dates and times, including:
date
: Represents a date (year, month, day) without a time zone.datetime
: Represents a date and time (year, month, day, hour, minute, second, microsecond) with a time zone.time
: Represents a time (hour, minute, second, microsecond) without a date or time zone.Temps 3 provides several functions for performing operations on dates and times, including:
strftime
: Formats a date or time as a string.strptime
: Parses a string into a date or time object.timedelta
: Represents a duration or difference between two dates or times.tzinfo
: Represents a time zone.Here is an example usage of Temps 3:
import temps3
# Create a date object
d = temps3.date(2021, 8, 26)
# Print the date as a string
print(d.strftime('%Y-%m-%d'))
# Create a time object
t = temps3.time(12, 34, 56)
# Print the time as a string
print(t.strftime('%H:%M:%S'))
# Create a datetime object
dt = temps3.datetime(2021, 8, 26, 12, 34, 56)
# Print the datetime as a string
print(dt.strftime('%Y-%m-%d %H:%M:%S'))
# Create a timedelta
td = temps3.timedelta(hours=1, minutes=30)
# Add timedelta to datetime
new_dt = dt + td
# Print new datetime as a string
print(new_dt.strftime('%Y-%m-%d %H:%M:%S'))
This will output:
2021-08-26
12:34:56
2021-08-26 12:34:56
2021-08-26 14:04:56
Temps 3 is a powerful tool for managing dates and times in Python programs. With its rich set of classes and functions, developers can easily manage and manipulate time-related data.