1、简单的获取
import time
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime())
now2 = time.strftime("%Y-%m-%d", time.localtime())
print (now)
print (now2)
2、另一种获取方式
from datetime import datetime
now = datetime.now()
year = str(int(now.strftime('%Y')))
month = str(int(now.strftime('%m')))
day = str(int(now.strftime('%d')))
time = year+'-'+month+'-'+day
print (time)