“Wie schreibe ein Date mit TH und ND in Python” Code-Antworten

Wie schreibe ein Date mit TH und ND in Python

from datetime import datetime as dt

def suffix(d):
    return 'th' if 11<=d<=13 else {1:'st',2:'nd',3:'rd'}.get(d%10, 'th')

def custom_strftime(format, t):
    return t.strftime(format).replace('{S}', str(t.day) + suffix(t.day))

print custom_strftime('%B {S}, %Y', dt.now())
Crowded Caribou

Wie schreibe ein Date mit TH und ND in Python

from datetime import datetime as dt

def suffix(d):
    return 'th' if 11<=d<=13 else {1:'st',2:'nd',3:'rd'}.get(d%10, 'th')

def custom_strftime(format, t):
    return t.strftime(format).replace('{S}', str(t.day) + suffix(t.day))

print custom_strftime('%B {S}, %Y', dt.now())
Crowded Caribou

Ähnliche Antworten wie “Wie schreibe ein Date mit TH und ND in Python”

Fragen ähnlich wie “Wie schreibe ein Date mit TH und ND in Python”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen