python_日期和时间

1、打印月历

>>> import calendar
>>> cal = calendar.month(2018,1)
>>> print(cal)
January 2018
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

2、

import time;  # 引入time模块
ticks = time.time()
print ("当前时间戳为:", ticks)

输出结果:

当前时间戳为: 1459996086.7115328

3、
import time
localtime = time.localtime(time.time())
print ("本地时间为 :", localtime)
输出结果:
本地时间为 : time.struct_time(tm_year=2016, tm_mon=4, tm_mday=7, tm_hour=10, tm_min=28, tm_sec=49, tm_wday=3, tm_yday=98, tm_isdst=0)

4、
import time
# 格式化成2016-03-20 11:45:39形式
print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))


参考: https://blog.csdn.net/qq_17119267/article/details/79410992

原文地址:https://www.cnblogs.com/leochan007/p/9680223.html