美文网首页
Python获取时间

Python获取时间

作者: 峰峰仔 | 来源:发表于2019-01-18 14:47 被阅读0次
  1. 获取当前时间
    代码:
import datetime

now = datetime.datetime.now()

print "current date and time %s" % str(now)

print "current year: %d" % now.year
print "current month: %d" % now.month
print "current day: %d" % now.day
print "current hour: %d" % now.hour
print "current minute: %d" % now.minute
print "current second: %d" % now.second
print "current microsecond: %d" % now.microsecond
print "current date and time %s" % now.strftime("%Y-%m-%d %H:%M")

输出:

current date and time 2019-01-18 14:45:03.897120
current year: 2019
current month: 1
current day: 18
current hour: 14
current minute: 45
current second: 3
current microsecond: 897120
current date and time 2019-01-18 14:45

相关文章

网友评论

      本文标题:Python获取时间

      本文链接:https://www.haomeiwen.com/subject/ubsndqtx.html