python 获取当前时间 分解为年、月、日、小时、分钟

布满荆棘的人生 2022-01-27 01:21 612阅读 0赞

方法一:

  1. import datetime now = datetime.datetime.now()
  2. print now.year, now.month, now.day, now.hour, now.minute, now.second

输出结果:
# 2015 5 6 8 53 40

不需要单独的变量,返回datetime对象。

方法二:

  1. import time
  2. strings = time.strftime("%Y,%m,%d,%H,%M,%S")
  3. t = strings.split(',')
  4. numbers = [ int(x) for x in t ]
  5. print numbers

输出结果:

  1. [2016, 3, 11, 8, 29, 47]

发表评论

表情:
评论列表 (有 0 条评论,612人围观)

还没有评论,来说两句吧...

相关阅读