python 获取年月日

简介: import datetimedatetime.datetime.now().yeardatetime.datetime.now().monthdatetime.

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

目录
相关文章
|
5月前
|
Python
「Python系列」Python 日期和时间
Python 提供了多个内置模块来处理日期和时间,其中最常用的是 `datetime` 模块。这个模块提供了类来操作日期、时间、日期和时间间隔。
62 0
|
5月前
|
Unix 数据处理 Python
Python中日期时间的处理
Python中日期时间的处理
56 0
|
5月前
|
Python
python获取当前日期
python获取当前日期
44 1
|
5月前
|
调度 Python
Python 日期
Python 日期
41 0
|
5月前
|
Python
python字符串转为datetime
在Python中,timedelta对象是用于表示时间间隔的,它常常被用来计算两个日期或时间之间的差值,有时我们可能需要将timedelta对象转换为字符串,以便于阅读和记录,以下是如何将timedelta对象转换为字符串的详细步骤:
|
Shell Python
python中练习求几天后星期几问题
python中练习求几天后星期几问题
230 0
|
Python
Python 日期时间库datetime常用函数
Python 日期时间库datetime常用函数
105 0
|
C++ Python
捋一捋python日期时间处理(下)
正式的Python专栏第33篇,同学站住,别错过这个从0开始的文章!
133 0
捋一捋python日期时间处理(下)
|
Java Python 容器
捋一捋操作python日期时间处理(上)
正式的Python专栏第32篇,同学站住,别错过这个从0开始的文章!
120 0
捋一捋操作python日期时间处理(上)
|
Python
python| python中日期时间处理
再强调下最佳实践: - 所有处理都在 UTC 下, 只在需要 fmt 时转成对应时区 - ts 即 UTC, 需要 tz 信息进行 fmt - 不建议使用不带时区信息的日期时间表示格式(st dt str)
373 0