import time
ticks = time.time()
print ("当前时间戳为:", ticks)
localtime = time.localtime(time.time())
print ("当前时间为 :", localtime)
localtime = time.asctime( time.localtime(time.time()) )
print ("获取格式化时间为 :", localtime)
# 格式化成2016-03-20 11:45:39形式
print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
# 格式化成Sat Mar 28 22:24:24 2016形式
print (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
# 将格式字符串转换为时间戳
a = "Sat Mar 28 22:24:24 2016"
print (time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))
#获取某月日历
cal = calendar.month(2016, 1)
print (cal)
time模块-日期和时间
最新推荐文章于 2024-07-07 04:03:03 发布