1. 程式人生 > >Getting today’s date in YYYY-MM-DD in Python?

Getting today’s date in YYYY-MM-DD in Python?

天呀,好神奇的簡單!

import datetime

datetime.datetime.today().strftime('%Y-%m-%d')

輸出的結果:

2017-09-15

The datetime module is your friend:

import datetime
now = datetime.datetime.now()
print now.year, now.month, now.day, now.hour, now.minute, now.second
# 2015 5 6 8 53 40