How to print a date in a regular format?

后端 未结 22 2782
孤街浪徒
孤街浪徒 2020-11-21 23:00

This is my code:

import datetime
today = datetime.date.today()
print(today)

This prints: 2008-11-22 which is exactly what I wa

22条回答
  •  太阳男子
    2020-11-21 23:44

    Or even

    from datetime import datetime, date
    
    "{:%d.%m.%Y}".format(datetime.now())
    

    Out: '25.12.2013

    or

    "{} - {:%d.%m.%Y}".format("Today", datetime.now())
    

    Out: 'Today - 25.12.2013'

    "{:%A}".format(date.today())
    

    Out: 'Wednesday'

    '{}__{:%Y.%m.%d__%H-%M}.log'.format(__name__, datetime.now())
    

    Out: '__main____2014.06.09__16-56.log'

提交回复
热议问题