python获取时间

Posted _刘文凯_

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python获取时间相关的知识,希望对你有一定的参考价值。

python获取时间

import datetime

# 获得当前时间
now = datetime.datetime.now()

other_StyleTime = now.strftime("%Y-%m-%d %H:%M:%S")

Y = now.strftime("%Y")
M = now.strftime("%m")
D = now.strftime("%d")


print(Y, M, D)

获取时间的格式

"%Y-%m-%d %H:%M:%S"

以上是关于python获取时间的主要内容,如果未能解决你的问题,请参考以下文章