Python: convert Unicode string to MM / DD / YYYY

I have a unicode string like u'Mar232012 ' . I want to convert it to MM / DD / YYYY format using python in post efficiently and reliably.

+4
source share
1 answer
import datetime datetime.datetime.strptime(u'Mar232012', '%b%d%Y').strftime('%m/%d/%Y') 

prints '03/23/2012'

+11
source

Source: https://habr.com/ru/post/1403631/


All Articles