-6

I want this string "20180425.142117" to convert to human readable format. E.g. 25th April 2018, 2:21 pm in Python

Any ideas how to do this?

AS_ON
  • 173
  • 2
  • 7
  • What representation is that? Have you tried googling? – bosnjak Apr 25 '18 at 22:30
  • 1
    `datetime.datetime.strptime("20180425.142117", "%Y%m%d.%H%M%S").ctime()` -- See https://docs.python.org/3.6/library/datetime.html#strftime-strptime-behavior – Robᵩ Apr 25 '18 at 22:32

1 Answers1

1

Try using the datetime library.

import datetime as dt
time_str = "20180425.142117"
# Convert to a datetime 
time_dt = dt.datetime.strptime(time_str, '%Y%m%d.%H%M%S')
# Convert back to string with the right format
human_time = dt.datetime.strftime(time_dt, '%dth %b %Y, %I:%M%p')
print(human_time)

I have to say that I look up the codes each time I need to do something custom.

vijayshankarv
  • 325
  • 2
  • 6