0

I used strptime() with format '%d %a %Y %-Ip%' but it's throwing the error stating "-I" is bad directive.

2 Answers2

0

You have your time format wrong. %-Ip% is not a valid format (should be %I%p), and %a is also incorrect for parsing dec (should be %b%).

The following example shows the output with the format %d %b %Y %I%p:

import time

struct_time = time.strptime("6 dec 2019 9pm", "%d %b %Y %I%p")
print(struct_time)

Output:

time.struct_time(tm_year=2019, tm_mon=12, tm_mday=6, tm_hour=21, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=340, tm_isdst=-1)
Martin
  • 16,093
  • 1
  • 29
  • 48
0

You can use datetime

from datetime import datetime
datetime.strptime('6 dec 2019 9pm', '%d %b %Y %I%p')
Bilal Zaib
  • 21
  • 4