Moment is a Python library designed for simplifying date and time manipulation, drawing inspiration from Moment.js and Kenneth Reitz's Requests library. It provides an intuitive API for parsing, formatting, and performing calculations with dates and times. The library is currently at version 0.12.1, but its GitHub repository shows no activity since 2015, and it is explicitly labeled as deprecated by recent analyses, with recommendations to use more actively maintained alternatives like `arrow` or `pendulum`.
pip install momentVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create moment objects from current time or strings, perform basic arithmetic operations like adding time, and convert them to standard `datetime` objects. It also highlights the use of `clone()` to handle mutability.
Migrate to `arrow` (e.g., `pip install arrow`) or `pendulum` (e.g., `pip install pendulum`). These libraries offer similar or enhanced functionality with active development and better timezone support.
Always use `.clone()` before performing operations that should not alter the original moment object. Example: `new_moment = original_moment.clone().add(days=1)`.
For applications requiring precise and up-to-date timezone awareness, particularly across different regions and DST transitions, consider `pendulum` which is built for strict timezone handling, or `arrow` for a more user-friendly API with timezone awareness. Carefully test all timezone-sensitive operations if you must use `moment`.
Run `pip install moment` in your terminal to install the package.
Consult the `zachwill/moment` GitHub README for available methods. If expecting a non-mutated object, ensure you've used `.clone()` before modification. If you are expecting `Moment.js` functionality, be aware that this is a Python port and not all features are identical. Consider `arrow` or `pendulum` if core `moment` functionality is missing or problematic.
Ensure all `datetime` objects you are comparing are either consistently naive or consistently aware. When converting from `moment` to `datetime`, explicitly handle timezones. For example, `my_moment.date.replace(tzinfo=desired_timezone)` or ensure `moment` objects are consistently aware with `.utcnow()` or `.timezone()` methods, and then use `moment_obj.datetime` to get an aware `datetime`.
No dependency data recorded yet.