Python基础之时间、日历

1.时间。

  通过时间格式化函数可以获取当前时间年份、月份、日期、时、分、秒。

2.日历。

  通过日历书函数可以获取日期相关信息。

相关代码:

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import time
>>> print(time.time())
1498398305.31976
>>> print(time.localtime())
time.struct_time(tm_year=2017, tm_mon=6, tm_mday=25, tm_hour=21, tm_min=46, tm_sec=47, tm_wday=6, tm_yday=176, tm_isdst=0)
>>> currentTime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
>>> print(currentTime)
2017-06-25 21:48:46
>>> import calendar
>>> cal = calendar.month(2016, 1)
>>> print("以下输出2016年1月份的日历:")
以下输出2016年1月份的日历:
>>> print(cal)
    January 2016
Mo Tu We Th Fr Sa Su
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

>>> 
原文地址:https://www.cnblogs.com/joyet-john/p/7078139.html