import time


print(time.time())      # 当前时间秒
print(time.ctime())     # 当前时间字符串
print(time.ctime(1))    # 绝对秒的 时间字符串
print(time.localtime())     # 秒到9元组的转换
print(time.asctime())
print(time.asctime((2017, 10, 13, 13, 29, 18, 4, 286, 0)))  # 9元组到时间字符串转换
print(time.mktime(time.localtime()))    # 9元组到秒的转换

# 时间格式化
print(time.strftime('%Y-%m-%d %H:%M:%S'))
print(time.strftime('%H:%M:%S %m/%d/%Y'))
print(time.strftime('%Y-%m-%d'))
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()-3600)))     # 获取一个小时前的时间

# 字符串转time对象
print(time.strptime('2017-03-15 08:00:00', '%Y-%m-%d %H:%M:%S'))
print(time.strptime('17:27:33 03/18/2017', '%H:%M:%S %m/%d/%Y'))

