Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Convert unicode string to MM/DD/YYYY

I have a unicode string for example u'Mar232012'. I want to convert it to the format MM/DD/YYYY using python in the post efficient and reliable manner.

like image 477
Zain Khan Avatar asked Dec 22 '22 00:12

Zain Khan


1 Answers

import datetime

datetime.datetime.strptime(u'Mar232012', '%b%d%Y').strftime('%m/%d/%Y')

prints '03/23/2012'

like image 57
eumiro Avatar answered Jan 11 '23 23:01

eumiro