How to print a date in a regular format?

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

    import datetime
    import time
    
    months = ["Unknown","January","Febuary","Marchh","April","May","June","July","August","September","October","November","December"]
    datetimeWrite = (time.strftime("%d-%m-%Y "))
    date = time.strftime("%d")
    month= time.strftime("%m")
    choices = {'01': 'Jan', '02':'Feb','03':'Mar','04':'Apr','05':'May','06': 'Jun','07':'Jul','08':'Aug','09':'Sep','10':'Oct','11':'Nov','12':'Dec'}
    result = choices.get(month, 'default')
    year = time.strftime("%Y")
    Date = date+"-"+result+"-"+year
    print Date
    

    In this way you can get Date formatted like this example: 22-Jun-2017

提交回复
热议问题