
Timestamp = datetime. timestamp time.strftime('l:M:S') However, this prints the format in a 12-hour format.

What strptime actually wanted was a 12, not a zero: > datetime.strptime('1 12:12am', "%Y/%m/%d %I:%M%p")īut we don't always control our data sources! My solution for this edge case was to catch the exception, try parsing it with a %H, with a quick check that we are in the edge case we think we are in. Currently I'm creating timestamps with the Python time module. import datetime is use to import the date and time modules After importing date time module next step is to accept date string as an input and then store it.

ValueError: time data '1 0:12am' does not match format '%Y/%m/%d %I:%M' In python, we have the strptime() method, which is mostly in its datetime class, and in order to convert any string representation for the date/time into a. But depending on your data source, you might get data that says that midnight or midday is actually zero, eg: > datetime.strptime('1 0:12am', "%Y/%m/%d %I:%M%p") I have gone through time library of python but couldn't come up with any solution. I need to convert into same format but with time in 12-Hrs format. The %I formatter is meant to match 12-hour-clock hours, optionally zero-padded. I have a string containing time stamp in format (DD/MM/YYYY HH:MM:SS AM/PM), e.g.' 15:25:05 pm'. Just in case this answer helps someone else - I came here thinking I had a problem with zero padding, but it was actually to do with 12:00 vs 00:00 and the %I formatter.
