Python获取当前年月日

时间:2024-12-13 14:33:14
import datetime
datetime.datetime.now().year
datetime.datetime.now().month
datetime.datetime.now().day # 示例
ubuntu@ThinkCentre:~$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.now().year
2017
>>> datetime.datetime.now().month
3
>>> datetime.datetime.now().day
23