How to print a date in a regular format?

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

    import datetime
    print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
    

    Edit:

    After Cees' suggestion, I have started using time as well:

    import time
    print time.strftime("%Y-%m-%d %H:%M")
    

提交回复
热议问题