Reputation: 199
I have a str 'Jan 22 16:47:37',I want to convert it to time type.
datetime.strptime('Jan 22 16:47:37', "%b %d %H:%M:%S")
I get
datetime.datetime(1900, 1, 22, 16, 47, 37)
I hope the result of the code is datetime.datetime( 1, 22, 16, 47, 37)
How can I do?
Thanks
Upvotes: 0
Views: 44
Reputation: 2602
You could do this:
value=datetime.strptime('Jan 22 16:47:37', "%b %d %H:%M:%S")
(value.month,value.day,value.hour,value.minute,value.second)
You can't get a datetime object without the year. Refer to the definition of datetime object
?datetime
Docstring:
datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
The year, month and day arguments are required. tzinfo may be None, or an
instance of a tzinfo subclass. The remaining arguments may be ints or longs.
Type: type
Upvotes: 1