Zain Khan
Zain Khan

Reputation: 3793

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.

Upvotes: 4

Views: 8358

Answers (1)

eumiro
eumiro

Reputation: 213025

import datetime

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

prints '03/23/2012'

Upvotes: 11

Related Questions