这是我的代码:
import datetime
today = datetime.date.today()
print(today)
这张照片是:2008-11-22,这正是我想要的。
但是,我有一个列表,我要将其附加到列表中,然后突然一切都变得“不稳定”。代码如下:
import datetime
mylist = []
today = datetime.date.today()
mylist.append(today)
print(mylist)
这将打印以下内容:
[datetime.date(2008, 11, 22)]
我怎样才能得到像2008-11-22这样的简单约会?
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
通过这种方式,您可以获得如下格式的日期:2017年6月22日