0

I want to convert datetime string to datetime format. I already tried with datetime.strptime but this code doesn't covert to datetime format.

In python 3.0 version, I tried strptime and parse to covert to datetime format.

nut_time_ = (nut_unique_date + ' ' + nut_unique_time)

print(nut_time)

nut_time_ = datetime.datetime.strptime(nut_time_, '%Y-%m-%d %H:%M:%S')

print(nut_time)

The format that I want to get is : datetime.datetime(2013, 1, 6, 20, 33, 42)

But the actual results is : 2013-01-06 20:33:42

1 Answer 1

2

Quick answer:

print(repr(nut_time_))

The issue is whether you want to print(str(nut_time_)) or the repr version. The former is what you get. So nothing wrong with you. The latter is what you usually see in the Python REPL. If you use print() function to print some stuff, by default it will give you the str representation.

Sign up to request clarification or add additional context in comments.

2 Comments

Then how can I make like this? 2013, 1, 6, 20, 33, 42 Is it already covert to that format? I plan to calculate the two different datetime duration, so I need that format.
To convert to a format: print(nut_time_.strftime("%Y, %m, %d, %H, %M, %S")), or read the datetime manual to extract each items you want (if you find the difference, the object is called timedelta)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.