How to print a date in a regular format?

后端 未结 22 2776
孤街浪徒
孤街浪徒 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:31

    I hate the idea of importing too many modules for convenience. I would rather work with available module which in this case is datetime rather than calling a new module time.

    >>> a = datetime.datetime(2015, 04, 01, 11, 23, 22)
    >>> a.strftime('%Y-%m-%d %H:%M')
    '2015-04-01 11:23'
    

提交回复
热议问题