Title: [How-to] - How to convert string to pendulum · python-pendulum/pendulum · Discussion #651 · GitHub
Open Graph Title: [How-to] - How to convert string to pendulum · python-pendulum/pendulum · Discussion #651
X Title: [How-to] - How to convert string to pendulum · python-pendulum/pendulum · Discussion #651
Description: [How-to] - How to convert string to pendulum
Open Graph Description: Hello beautiful people! I have for hours and hours trying to figure out how to use pendulum in a case which is super hard. I have a text that returns 01-06-08-45 which means: Closing in : 1 day, 6 ...
X Description: Hello beautiful people! I have for hours and hours trying to figure out how to use pendulum in a case which is super hard. I have a text that returns 01-06-08-45 which means: Closing in : 1 day, 6 ...
Opengraph URL: https://github.com/python-pendulum/pendulum/discussions/651
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"[How-to] - How to convert string to pendulum","text":"\u003cp dir=\"auto\"\u003eHello beautiful people!\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eI have for hours and hours trying to figure out how to use pendulum in a case which is super hard. I have a text that returns\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003ccode class=\"notranslate\"\u003e01-06-08-45\u003c/code\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003ewhich means:\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eClosing in : 1 day, 6 hours, 8 minutes and 45 seconds.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eand I want to be able to convert this into pendulum.format/parse (so I have something like 2022-09-01 12:00:00)\u003cbr\u003e\nI have currently done something like this:\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"t = '01-06-08-45'\ntest = pendulum.duration(days=float(t.split('-')[0]), hours=float(t.split('-')[1]), minutes=float(t.split('-')[2]), seconds=float(t.split('-')[3]))\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003et = '01-06-08-45'\ntest = pendulum.duration(days=float(t.split('-')[0]), hours=float(t.split('-')[1]), minutes=float(t.split('-')[2]), seconds=float(t.split('-')[3]))\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003ewhich returns \u003ccode class=\"notranslate\"\u003e1 day 6 hours 8 minutes 45 seconds\u003c/code\u003e but my question is how can I convert this into a format of e.g. \u003ccode class=\"notranslate\"\u003e2022-09-01 12:00:00\u003c/code\u003e instead? Is that possible using Pendulum?\u003c/p\u003e","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\u003cp dir=\"auto\"\u003eHi \u003ca class=\"user-mention notranslate\" data-hovercard-type=\"user\" data-hovercard-url=\"/users/BarryAljawari/hovercard\" data-octo-click=\"hovercard-link-click\" data-octo-dimensions=\"link_type:self\" href=\"https://github.com/BarryAljawari\"\u003e@BarryAljawari\u003c/a\u003e - I think you need to make your question more clear. You are creating a pendulum.Duration object (something that represents a length of time), yet you want to display a format that only makes sense for a pendulum.Datetime object (something that designates a particular moment in time).\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you want to explore different ways of turning a duration into a string, have a look at the docs about them: \u003ca href=\"https://pendulum.eustace.io/docs/#properties-and-duration-methods\" rel=\"nofollow\"\u003ehttps://pendulum.eustace.io/docs/#properties-and-duration-methods\u003c/a\u003e . If you want to convert the Duration into a DateTime, you have to realize that doesn't make sense without more context. That's like saying, I'm going to wait for 4 hours and 52 minutes; express that as a calendar year, month, date, hour and minute.\u003c/p\u003e","upvoteCount":1,"url":"https://github.com/python-pendulum/pendulum/discussions/651#discussioncomment-3612700"}}}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/discussions/:number(.:format) |
| route-controller | discussions |
| route-action | show |
| fetch-nonce | v2:1b20109d-79e1-2129-0a9a-ebef2aab920e |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | CC3A:83A5C:23A29E:308B3B:6B046863 |
| html-safe-nonce | ea5b30cbb24f3032802729cd4b9b44270ba2c9e7810d261d75ed88bec0ada52a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzNBOjgzQTVDOjIzQTI5RTozMDhCM0I6NkIwNDY4NjMiLCJ2aXNpdG9yX2lkIjoiMTMwNjA3MTQwNzI5MzM5Mjk5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4390dfc26c8f9dd3b2ce1093fa4f820ac8a0b2f4d2c8b850bf3e3c4d605c3ee |
| hovercard-subject-tag | discussion:4379770 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-pendulum/pendulum/discussions/651 |
| twitter:image | https://opengraph.githubassets.com/06286b9cab03389a89a967aec29aa8c58230400d8e7081b0ff3f797060878b18/python-pendulum/pendulum/discussions/651 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/06286b9cab03389a89a967aec29aa8c58230400d8e7081b0ff3f797060878b18/python-pendulum/pendulum/discussions/651 |
| og:image:alt | Hello beautiful people! I have for hours and hours trying to figure out how to use pendulum in a case which is super hard. I have a text that returns 01-06-08-45 which means: Closing in : 1 day, 6 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git |
| octolytics-dimension-user_id | 191041900 |
| octolytics-dimension-user_login | python-pendulum |
| octolytics-dimension-repository_id | 62095504 |
| octolytics-dimension-repository_nwo | python-pendulum/pendulum |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62095504 |
| octolytics-dimension-repository_network_root_nwo | python-pendulum/pendulum |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width