{"id":13502140,"url":"https://github.com/zachwill/moment","last_synced_at":"2025-03-29T10:32:46.989Z","repository":{"id":6009748,"uuid":"7232992","full_name":"zachwill/moment","owner":"zachwill","description":"A Python library for dealing with dates","archived":false,"fork":false,"pushed_at":"2023-04-24T14:49:02.000Z","size":81,"stargazers_count":734,"open_issues_count":6,"forks_count":49,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-03T14:46:21.316Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zachwill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2012-12-19T01:00:31.000Z","updated_at":"2025-02-22T20:54:55.000Z","dependencies_parsed_at":"2024-01-29T18:51:44.813Z","dependency_job_id":null,"html_url":"https://github.com/zachwill/moment","commit_stats":{"total_commits":147,"total_committers":4,"mean_commits":36.75,"dds":0.04081632653061229,"last_synced_commit":"7a5bfaeabd016c69f0a9607a50978aac65c3e2ef"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachwill%2Fmoment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachwill%2Fmoment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachwill%2Fmoment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachwill%2Fmoment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zachwill","download_url":"https://codeload.github.com/zachwill/moment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174207,"owners_count":20735406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T22:02:03.415Z","updated_at":"2025-03-29T10:32:46.599Z","avatar_url":"https://github.com/zachwill.png","language":"Python","funding_links":[],"categories":["Date and Time","资源列表","Python","📦 Packages","日期和时间","Date and Time [🔝](#readme)","Uncategorized","Awesome Python"],"sub_categories":["日期和时间","Python","Automatic Plotting","Uncategorized","Date and Time"],"readme":"moment\n======\n\nA Python library for dealing with dates/times. Inspired by [**Moment.js**][moment] and\nKenneth Reitz's [**Requests**][requests] library. Ideas were also taken from the\n[**Times**][times] Python module.\n\n[moment]: http://momentjs.com/docs/\n[requests]: http://docs.python-requests.org/\n[times]: https://github.com/nvie/times\n\n\nInstallation\n------------\n\nI would advise that this is beta-quality software. You might be interested in:\n\n- the [`arrow` package][arrow]\n- the [`pendulum` package][pendulum]\n\n[arrow]: https://github.com/crsmithdev/arrow/\n[pendulum]: https://github.com/sdispater/pendulum\n\nStill want to use `moment`?\n\n`pip install moment`\n\n\nUsage\n-----\n\n```python\nimport moment\nfrom datetime import datetime\n\n# Create a moment from a string\nmoment.date(\"12-18-2012\")\n\n# Create a moment with a specified strftime format\nmoment.date(\"12-18-2012\", \"%m-%d-%Y\")\n\n# Moment uses the awesome dateparser library behind the scenes\nmoment.date(\"2012-12-18\")\n\n# Create a moment with words in it\nmoment.date(\"December 18, 2012\")\n\n# Create a moment that would normally be pretty hard to do\nmoment.date(\"2 weeks ago\")\n\n# Create a moment from the current datetime\nmoment.now()\n\n# The moment can also be UTC-based\nmoment.utcnow()\n\n# Create a moment with the UTC time zone\nmoment.utc(\"2012-12-18\")\n\n# Create a moment from a Unix timestamp\nmoment.unix(1355875153626)\n\n# Create a moment from a Unix UTC timestamp\nmoment.unix(1355875153626, utc=True)\n\n# Return a datetime instance\nmoment.date(2012, 12, 18).date\n\n# We can do the same thing with the UTC method\nmoment.utc(2012, 12, 18).date\n\n# Create and format a moment using Moment.js semantics\nmoment.now().format(\"YYYY-M-D\")\n\n# Create and format a moment with strftime semantics\nmoment.date(2012, 12, 18).strftime(\"%Y-%m-%d\")\n\n# Use the special `%^` combo to add a date suffix (1st, 2nd, 3rd, 4th, etc)\nmoment.date(2012, 12, 18).strftime(\"%B %-d%^, %Y\")\n\n# Update your moment's time zone\nmoment.date(datetime(2012, 12, 18)).locale(\"US/Central\").date\n\n# Alter the moment's UTC time zone to a different time zone\nmoment.utcnow().timezone(\"US/Eastern\").date\n\n# Set and update your moment's time zone. For instance, I'm on the\n# west coast, but want NYC's current time.\nmoment.now().locale(\"US/Pacific\").timezone(\"US/Eastern\")\n\n# In order to manipulate time zones, a locale must always be set or\n# you must be using UTC.\nmoment.utcnow().timezone(\"US/Eastern\").date\n\n# You can also clone a moment, so the original stays unaltered\nnow = moment.utcnow().timezone(\"US/Pacific\")\nfuture = now.clone().add(weeks=2)\n```\n\nChaining\n--------\n\nMoment allows you to chain commands, which turns out to be super useful.\n\n```python\n# Customize your moment by chaining commands\nmoment.date(2012, 12, 18).add(days=2).subtract(weeks=3).date\n\n# Imagine trying to do this with datetime, right?\nmoment.utcnow().add(years=3, months=2).format(\"YYYY-M-D h:m A\")\n\n# You can use multiple keyword arguments\nmoment.date(2012, 12, 19).add(hours=1, minutes=2, seconds=3)\n\n# And, a similar subtract example...\nmoment.date(2012, 12, 19, 1, 2, 3).subtract(hours=1, minutes=2, seconds=3)\n\n# In addition to adding/subtracting, we can also replace values\nmoment.now().replace(hours=5, minutes=15, seconds=0).epoch()\n\n# And, if you'd prefer to keep the microseconds on your epoch value\nmoment.now().replace(hours=5, minutes=15, seconds=0).epoch(rounding=False)\n\n# Years, months, and days can also be set\nmoment.now().replace(years=1984, months=1, days=1, hours=0, minutes=0, seconds=0)\n\n# Also, datetime properties are available\nmoment.utc(2012, 12, 19).year == 2012\n\n# Including plural ones (since I'm bad at remembering)\nmoment.now().seconds\n\n# We can also manipulate to preferred weekdays, such as Monday\nmoment.date(2012, 12, 19).replace(weekday=1).strftime(\"%Y-%m-%d\")\n\n# Or, this upcoming Sunday\nmoment.date(\"2012-12-19\").replace(weekday=7).date\n\n# We can even go back to two Sundays ago\nmoment.date(2012, 12, 19).replace(weekday=-7).format(\"YYYY-MM-DD\")\n\n# It's also available as a property\nmoment.utcnow().weekday\n\n# And, there's an easy way to zero out the hours, minutes, and seconds\nmoment.utcnow().zero\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachwill%2Fmoment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzachwill%2Fmoment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachwill%2Fmoment/lists"}