方法一:
import datetime now = datetime.datetime.now()
print now.year, now.month, now.day, now.hour, now.minute, now.second
输出结果:
# 2015 5 6 8 53 40
不需要单独的变量,返回datetime
对象。
方法二:
import time
strings = time.strftime("%Y,%m,%d,%H,%M,%S")
t = strings.split(',')
numbers = [ int(x) for x in t ]
print numbers
输出结果:
[2016, 3, 11, 8, 29, 47]