Python获取间隔时间段的时间戳数据

import time
import datetime today = datetime.datetime.now()
# delta = datetime.timedelta(hours=1)
delta = datetime.timedelta(days=7)
start = today - delta
dt = start.strftime("%Y-%m-%d %H:%M:%S")
timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
startts = int(time.mktime(timeArray)) * 1000000
print(startts)

另一种方法

import pytz
import time
import datetime tz = pytz.timezone('Asia/Shanghai')
now = datetime.datetime.now(tz)
sevendays = timedelta(days=8)
start = now - sevendays
start2 = datetime.datetime(start.year, start.month, start.day)
startts = int(time.mktime(start2.timetuple())*1000)
print(startts)

如果大神们有更好的写法,还望不吝赐教。

上一篇:jconsole工具使用----jvm内存泄漏问题


下一篇:PHP debug_backtrace() 函数打印调用处的调试信息