Home > Blockchain >  Convert Date time to human readable formate python
Convert Date time to human readable formate python

Time:03-24

I have a date time string something like this

2022-03-21 16:29:01.8593

but I want it to be like

 03/21/2022 02:16 PM

CodePudding user response:

Use datetime module:

from datetime import datetime

d = datetime.strptime('2022-03-21 16:29:01.8593', '%Y-%m-%d %H:%M:%S.%f')
s = d.strftime('%m/%d/%Y %I:%M %p')

Output:

>>> d
datetime.datetime(2022, 3, 21, 16, 29, 1, 859300)

>>> s
'03/21/2022 04:29 PM'

Use this link as documentation.

  • Related