int to datetime in Python [duplicate]

2024/11/23 5:53:33

I'm receiving data from the port.

This data has date and time.But not formatted.

Example:

'02012019', '090253'

I want to save it to the database and I want to convert this format.

02-01-2019   09:02:53

Is there a function for this? Or is it a problem if I write? It will run 200 times in 5 seconds.

Anybody have a suggestion?

Answer
from datetime import datetimedate_data  ='02012019 09:02:53' 
data = datetime.strptime(date_data,'%d%m%Y %H:%M:%S')
result = data.strftime('%d-%m-%Y %H:%M:%S')# output '02-01-2019 09:02:53'
https://en.xdnf.cn/q/120656.html

Related Q&A

How to extract the historical tweets from twitter API? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

ValueError: invalid literal for int() with base 16: [closed]

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…

Modify list in Python [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

How to delete files inside hidden folder with python? [duplicate]

This question already has answers here:How can I delete a file or folder in Python?(18 answers)Closed 5 years ago.I want do delete a file, for ex. myfile.txt that is stored under a hidden folder. Is i…

Matching keywords in a dictionary to a list in Python

The following dictionary gives the word and its value:keywords = {alone: 1, amazed: 10, amazing: 10, bad: 1, best: 10, better: 7, excellent: 10, excited: 10, excite: 10}Following the dictionary are two…

How to make case insensitive? [closed]

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…

Webpage data extraction automation using python and selenium webdriver [closed]

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…

Asking the user if they want to play again [duplicate]

This question already has answers here:Ask the user if they want to repeat the same task again(2 answers)Closed 5 years ago.Basically its a guessing game and I have literally all the code except for th…

IF statement (checking for a string in a list) behave weirdly [duplicate]

This question already has answers here:How to test multiple variables for equality against a single value?(31 answers)Closed 10 years ago.This will probably be a dumb question, but why does this piece…

filteration in txt file in python

I have too many lines like this:>ENSG00000100206|ENST00000216024|DMC1|2371|38568257;38570043|38568289;38570286 CTCAGACGTCGGGCCGACGCAAGGCCACGCGCGCGAACACACAGGTGCGGCCCCGGGCCA CACGCACACCGTACAC >ENSG0…