René's URL Explorer Experiment


Title: How to convert Period or Duration to proper string · python-pendulum/pendulum · Discussion #675 · GitHub

Open Graph Title: How to convert Period or Duration to proper string · python-pendulum/pendulum · Discussion #675

X Title: How to convert Period or Duration to proper string · python-pendulum/pendulum · Discussion #675

Description: How to convert Period or Duration to proper string

Open Graph Description: I want some kind of Duration with 6 minutes and 58 seconds to look like this when casted to str "0:06:58" Is there a builtin function for formatting Durations or I gotta do it by myself

X Description: I want some kind of Duration with 6 minutes and 58 seconds to look like this when casted to str "0:06:58" Is there a builtin function for formatting Durations or I gotta do it by myself

Opengraph URL: https://github.com/python-pendulum/pendulum/discussions/675

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"How to convert Period or Duration to proper string","text":"\u003cp dir=\"auto\"\u003eI want some kind of Duration with 6 minutes and 58 seconds to look like this when casted to str\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"\u0026quot;0:06:58\u0026quot;\"\u003e\u003cpre class=\"notranslate\"\u003e\u003cspan class=\"pl-s\"\u003e\"0:06:58\"\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eIs there a builtin function for formatting Durations or I gotta do it by myself\u003c/p\u003e","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\u003cp dir=\"auto\"\u003eFor that representation, convert the duration to a standard \u003ccode class=\"notranslate\"\u003edatetime.timedelta\u003c/code\u003e with \u003ccode class=\"notranslate\"\u003eas_timedelta()\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"import pendulum\n\nduration = pendulum.duration(minutes=6, seconds=58)\nprint(str(duration.as_timedelta()))\n# 0:06:58\"\u003e\u003cpre class=\"notranslate\"\u003e\u003cspan class=\"pl-k\"\u003eimport\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003ependulum\u003c/span\u003e\n\n\u003cspan class=\"pl-s1\"\u003eduration\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003ependulum\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eduration\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eminutes\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e6\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003eseconds\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e58\u003c/span\u003e)\n\u003cspan class=\"pl-en\"\u003eprint\u003c/span\u003e(\u003cspan class=\"pl-en\"\u003estr\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eduration\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eas_timedelta\u003c/span\u003e()))\n\u003cspan class=\"pl-c\"\u003e# 0:06:58\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eI checked this with Pendulum 3.2.0. \u003ccode class=\"notranslate\"\u003estr(duration)\u003c/code\u003e gives \u003ccode class=\"notranslate\"\u003e6 minutes 58 seconds\u003c/code\u003e, while \u003ccode class=\"notranslate\"\u003estr(duration.as_timedelta())\u003c/code\u003e gives the exact representation in your question. \u003ca href=\"https://github.com/python-pendulum/pendulum/blob/3.2.0/src/pendulum/duration.py#L292-L299\"\u003eThe implementation\u003c/a\u003e exposes the conversion and uses \u003ccode class=\"notranslate\"\u003ein_words()\u003c/code\u003e for the duration's own string representation.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eThis follows standard \u003ccode class=\"notranslate\"\u003etimedelta\u003c/code\u003e formatting: a 27-hour duration displays \u003ccode class=\"notranslate\"\u003e1 day, 3:00:00\u003c/code\u003e, and fractional seconds are included when present. If you want total hours such as \u003ccode class=\"notranslate\"\u003e27:00:00\u003c/code\u003e, that would need a custom format.\u003c/p\u003e","upvoteCount":1,"url":"https://github.com/python-pendulum/pendulum/discussions/675#discussioncomment-18846523"}}}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format)
route-controllervoltron_discussions_fragments
route-actiondiscussion_layout
fetch-noncev2:cb46ea58-c252-ddf0-a24a-6690ab542716
current-catalog-service-hash9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be
request-id826C:632D5:165E1A:1F4749:6B0465A8
html-safe-nonced92edb131a7389ed0db594edfd957aa9d910720a4e895acf7f0ec3a96b91657c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjZDOjYzMkQ1OjE2NUUxQToxRjQ3NDk6NkIwNDY1QTgiLCJ2aXNpdG9yX2lkIjoiNjEyMTAyMTI3MTMwOTU3NTU5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac4665c538835a472666def8abbbe8150dd3747d8e22f6c942e194f568f7a6f245
hovercard-subject-tagdiscussion:4583784
github-keyboard-shortcutsrepository,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/discussions_fragments/discussion_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-pendulum/pendulum/675/discussion_layout
twitter:imagehttps://opengraph.githubassets.com/634be4ef0501d761a88b65113e8512ff7d90098cefb86d9ae8d6c9021a73cdd1/python-pendulum/pendulum/discussions/675
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/634be4ef0501d761a88b65113e8512ff7d90098cefb86d9ae8d6c9021a73cdd1/python-pendulum/pendulum/discussions/675
og:image:altI want some kind of Duration with 6 minutes and 58 seconds to look like this when casted to str "0:06:58" Is there a builtin function for formatting Durations or I gotta do it by myself
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f
turbo-cache-controlno-preview
go-importgithub.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git
octolytics-dimension-user_id191041900
octolytics-dimension-user_loginpython-pendulum
octolytics-dimension-repository_id62095504
octolytics-dimension-repository_nwopython-pendulum/pendulum
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id62095504
octolytics-dimension-repository_network_root_nwopython-pendulum/pendulum
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseca4d07a7cef4e4b75f821dc25e7300d80c1450a9
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-pendulum/pendulum/discussions/675#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fdiscussions%2F675
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fdiscussions%2F675
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fdiscussions_fragments%2Fdiscussion_layout&source=header-repo&source_repo=python-pendulum%2Fpendulum
Reloadhttps://github.com/python-pendulum/pendulum/discussions/675
Reloadhttps://github.com/python-pendulum/pendulum/discussions/675
Reloadhttps://github.com/python-pendulum/pendulum/discussions/675
python-pendulumhttps://github.com/python-pendulum
pendulumhttps://github.com/python-pendulum/pendulum
Codehttps://github.com/python-pendulum/pendulum
Issues211 (211)https://github.com/python-pendulum/pendulum/issues
Pull requests96 (96)https://github.com/python-pendulum/pendulum/pulls
Discussionshttps://github.com/python-pendulum/pendulum/discussions
Actionshttps://github.com/python-pendulum/pendulum/actions
Projectshttps://github.com/python-pendulum/pendulum/projects
Security and qualityhttps://github.com/python-pendulum/pendulum/security
Insightshttps://github.com/python-pendulum/pendulum/insights
Answered https://github.com/python-pendulum/pendulum/discussions/675#discussioncomment-18846523
agammannhttps://github.com/agammann
Exenifix https://github.com/Exenifix
Q&Ahttps://github.com/python-pendulum/pendulum/discussions/categories/q-a
How to convert Period or Duration to proper string https://github.com/python-pendulum/pendulum/discussions/675#top
Exenifix https://github.com/Exenifix
Answered https://github.com/python-pendulum/pendulum/discussions/675#discussioncomment-18846523
agammannhttps://github.com/agammann
Return to tophttps://github.com/python-pendulum/pendulum/discussions/675#top
Please reload this pagehttps://github.com/python-pendulum/pendulum/discussions/675
https://github.com/python-pendulum/pendulum/discussions/675
Exenifix https://github.com/Exenifix
Nov 20, 2022 https://github.com/python-pendulum/pendulum/discussions/675#discussion-4583784
agammann https://github.com/agammann
Oct 10, 2026 https://github.com/python-pendulum/pendulum/discussions/675#discussioncomment-18846523
The implementationhttps://github.com/python-pendulum/pendulum/blob/3.2.0/src/pendulum/duration.py#L292-L299
View full answer https://github.com/python-pendulum/pendulum/discussions/675#discussioncomment-18846523
Oldest https://github.com/python-pendulum/pendulum/discussions/675?sort=old
Newest https://github.com/python-pendulum/pendulum/discussions/675?sort=new
Top https://github.com/python-pendulum/pendulum/discussions/675?sort=top
Please reload this pagehttps://github.com/python-pendulum/pendulum/discussions/675
https://github.com/python-pendulum/pendulum/discussions/675
agammann https://github.com/agammann
Oct 10, 2026 https://github.com/python-pendulum/pendulum/discussions/675#discussioncomment-18846523
The implementationhttps://github.com/python-pendulum/pendulum/blob/3.2.0/src/pendulum/duration.py#L292-L299
Exenifixhttps://github.com/Exenifix
Sign up for freehttps://github.com/join?source=comment-repo
Sign in to commenthttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fdiscussions%2F675
🙏 Q&A https://github.com/python-pendulum/pendulum/discussions/categories/q-a
https://github.com/Exenifix
https://github.com/agammann
https://github.com/python-pendulum/pendulum/discussions/675
https://github.com/settings/replies?return_to=1
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.