## 得到unix时间
import time,datetime

# 获取10位unix时间戳(精确到秒)
In [21]: int(time.mktime(datetime.datetime.now().timetuple()))
Out[21]: 1487127939

uninx_time = int(time.mktime(datetime.datetime.now().timetuple()))
## unix时间改为str
In [34]: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(uninx_time))
Out[34]: '2017-02-15 11:22:18'

时间差

## 获取十天前的时间

In [2]: import datetime

In [3]: datetime.datetime.now()+datetime.timedelta(days=-10)
Out[3]: datetime.datetime(2017, 2, 12, 17, 23, 23, 15818)