#coding=utf-8
import time
import datetime
if __name__ == "__main__":
# 今天
now = datetime.datetime.now()
print now.strftime('%Y-%m-%d %H:%M:%S')
print "%s-%s-%s %s:%s:%s" % (now.year, now.month, now.day, now.hour, now.minute, now.second)
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 前一天
now = datetime.datetime.now()
dt = now + datetime.timedelta(days=-1)
print dt.strftime('%Y-%m-%d %H:%M:%S')
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - 24 * 3600))
# 后一天
now = datetime.datetime.now()
dt = now + datetime.timedelta(days=1)
print dt.strftime('%Y-%m-%d %H:%M:%S')
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 24 * 3600))
# 前一小时
now = datetime.datetime.now()
dt = now - datetime.timedelta(hours=1)
print dt.strftime("%Y-%m-%d %H:%M:%S")
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - 1 * 3600))
# 时间戳 秒
print int(time.time())
# 时间戳 毫秒
print int(round(time.time() * 1000))
# 时间戳 to 日期
print datetime.datetime.fromtimestamp(1507630854)
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1507630854))
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 日期 to 时间戳
print time.mktime(time.strptime("2017-10-10", "%Y-%m-%d"))
print time.mktime(time.strptime("2017-10-10 10:10:10", "%Y-%m-%d %H:%M:%S"))