1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python获取当前时间年月日_Python获取当前时间日期

python获取当前时间年月日_Python获取当前时间日期

时间:2023-01-07 10:24:08

相关推荐

python获取当前时间年月日_Python获取当前时间日期

Python获取当前时间日期,注意:可根据需要指定格式输出 -

Python

#!/usr/bin/python3

#coding=gbk

import time

curtime1 = time.strftime(\%Y-%m-%d %H:%M:%S,time.localtime(time.time()))

curtime2 = time.strftime(\%Y/%m/%d %H:%M:%S,time.localtime(time.time()))

curtime3 = time.strftime("%Y-%m-%d %A %X", time.localtime(time.time()))

print("Current time = ", curtime1)

print("Current time2 = ", curtime2)

print("Current time3 = ", curtime3)

执行上面代码,得到类似以下的输出结果 -

Current time = -06-21 02:18:17

Current time2 = /06/21 02:18:17

Current time3 = -06-21 Wednesday 02:18:17

也可以用: print (list(time.localtime()))

结果是:

Python

print (list(time.localtime()))

[, 6, 21, 2, 21, 13, 2, 172, 0]

有关解释:

取得时间相关的信息的话,要用到time模块,p

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。