Search code examples
pythondatetimeepochstrptimestrftime

ISO time to Human readable time in python


I am using Python. My time format is like

2020-05-23T06:35:11.418279Z #May 23, 2020 at 12:05:11 PM GMT+05:30

I want to convert into human readable time like

23-05-2020 12:05 PM

I tried parser too. But no effect.

Can anyone help me with this?

Thanks in advance :)


Solution

  • import datetime, pytz
    isodate = '2020-05-23T06:35:11.418279Z'
    d = datetime.datetime.fromisoformat(isodate[:-1]).replace(tzinfo=pytz.utc) # we need to strip 'Z' before parsing
    print(d.astimezone(pytz.timezone('Asia/Kolkata')).strftime('%d-%m-%Y %I:%M %p'))