This seems to add the appropriate suffix, and remove the ugly leading zeroes in the day number:
#!/usr/bin/python
import time
day_endings = {
1: 'st',
2: 'nd',
3: 'rd',
21: 'st',
22: 'nd',
23: 'rd',
31: 'st'
}
def custom_strftime(format, t):
return time.strftime(format, t).replace('{TH}', str(t[2]) + day_endings.get(t[2], 'th'))
print custom_strftime('%B {TH}, %Y', time.localtime())