[Python] python返回当前日期和时间 →→→→→进入此内容的聊天室

来自 , 2020-02-19, 写在 Python, 查看 105 次.
URL http://www.code666.cn/view/48db7158
  1. import datetime
  2.  
  3. # Get a datetime object
  4. now = datetime.datetime.now()
  5.  
  6. # General functions
  7. print "Year: %d" % now.year
  8. print "Month: %d" % now.month
  9. print "Day: %d" % now.day
  10. print "Weekday: %d" % now.weekday() # Day of week Monday = 0, Sunday = 6
  11. print "Hour: %d" % now.hour
  12. print "Minute: %d" % now.minute
  13. print "Second: %d" % now.second
  14. print "Microsecond: %d" % now.microsecond
  15.  
  16. # ISO Functions
  17. print "ISO Weekday: %d" % now.isoweekday() # Day of week Monday = 1, Sunday = 7
  18. print "ISO Format: %s" % now.isoformat() # ISO format, e.g. 2010-12-24T07:10:52.458593
  19. print "ISO Calendar: %s" % str(now.isocalendar()) # Tuple of (ISO year, ISO week number, ISO weekday)
  20.  
  21. # Formatted date
  22. print now.strftime("%Y/%m/%d") #
  23. #//python/8033

回复 "python返回当前日期和时间"

这儿你可以回复上面这条便签

captcha