
Alternatives to Python datetime and dateutil
Alternatives to Python datetime and dateutil 관련


Python datetime
and dateutil
are a powerful combination of libraries when you’re working with dates and times. dateutil
is even recommended in the Python documentation. However, there are many other libraries that you can use to work with dates and times in Python. Some of these rely on datetime
and dateutil
, while others are completely independent replacements:
pytz
** provides time zone information similar todateutil
. It uses a somewhat different interface than the standarddatetime.tzinfo
, so be aware of the potential problems if you decide to use it.- Arrow provides a drop-in replacement for
datetime
. It’s inspired bymoment.js
, so if you’re coming from web development, then this might be a more familiar interface. - Pendulum provides another drop-in replacement for
datetime
. It includes a time zone interface and an improvedtimedelta
implementation. timofurrer/maya
provides a similar interface asdatetime
. It relies on Pendulum for parts of the parsing library.- dateparser provides an interface to generate
datetime
instances from human-readable text. It’s flexible and supports many languages.
In addition, if you work heavily with NumPy, Pandas, or other data science packages, then there are a few options that might be useful to you:
- NumPy provides a similar API to the built-in Python
datetime
library, but the NumPy version can be used in arrays. - Pandas provides support for time-series data in DataFrames, usually sequential values of time-based events, by using the NumPy
datetime
module. - cftime provides support for calendars other than the proleptic Gregorian calendar as well as other time units conforming to the Climate and Forecasting (CF) conventions. It’s used by the
xarray
package to provide time-series support.
Further Reading
Since programming with time can be so complicated, there are many resources on the web to help you learn more about it. Fortunately, this is a problem that many people who work in every programming language have thought about, so you can usually find information or tools to help with any problem you may have. Here’s a selected list of articles and videos that I found helpful in writing this tutorial:
- Daylight saving time and time zone best practices
- Storing UTC is not a Silver Bullet
- How to save datetimes for future events
- Coding Best Practices Using DateTime in the .NET Framework
- Computerphile: The Problem with Time & Timezones
- The Complexity of Time Data Programming
In addition, Paul Ganssle is a core contributor to CPython and the current maintainer of dateutil
. His articles and videos are a great resource for Python users: