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