Python获取当前年月日

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
posted @ 2017-03-23 14:07  bovenson  阅读(67016)  评论(2编辑  收藏  举报