Hours and time converting to a certain format [closed]
2024/11/20 20:44:32
I have been trying to change the following format of time 8.25 (fractional hours) to 8.15 meaning 8:15. And 17.75 to 17.45 meaning 17:45. The problem is that I specifically need that format (timedelta) e.g 17.45 with a point . instead of :.
Answer
This can be done conveniently by using the appropriate representation for your fractional hours, namely a timedelta. If the input is of datatype string, convert to float first.
Ex:
from datetime import datetime, timedeltafor td in [8.25, 17.75]:# add the duration as timedelta to an arbitrary date to get a time object:print((datetime(2020,1,1) + timedelta(hours=td)).time())
Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…
This question already has answers here:UnicodeEncodeError: ascii codec cant encode character u\xa0 in position 20: ordinal not in range(128)(34 answers)Closed last year.I am trying to send an email fro…
Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…
Im simply trying to push my Flask app to Heroku but I encountered the following error:
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python…
Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 6 years ago.Improve…
Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 3 years ago.Improve…
I am new to python, and Im trying to build a simple recording program. With the some help from my previous question, I was able to add a timestamp for each recorded fileEDIT:I did some research and dec…
Im just learning web scraping & want to output the result of this website to a csv file https://www.avbuyer.com/aircraft/private-jets
but am struggling with parsing the next pages
here is my code (…
Im trying to convert the total sum to a percentage by userid but an error pops up when I try to run the following program. The error is: name mark is not definedBelow is my code for views.pydef attStud…