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)
如果大神们有更好的写法,还望不吝赐教。
Python获取间隔时间段的时间戳数据的更多相关文章
- Python获取股票历史、实时数据与更新到数据库
要做量化投资,数据是基础,正所谓"巧妇难为无米之炊" 在免费数据方面,各大网站的财经板块其实已提供相应的api,如新浪.雅虎.搜狐...可以通过urlopen相应格式的网址获取数据 ...
- python获取指定时间段内的随机不重复的时间点
上篇 <python时间时分秒与秒数的互相转换>http://www.cnblogs.com/gayhub/p/6154707.html 提到了把时间转成秒数的方法, 这篇写写转换成秒数后 ...
- python获取本地时间,时间戳与日期格式相互转换
附上代码与运行结果截图: import time # 获取当前时间 now = time.localtime() # 格式化日期 now_ = time.strftime('%Y-%m-%d %H:% ...
- python获取风和天气城市数据 ID
import requestsurl='https://cdn.heweather.com/china-city-list.csv'strhtml=requests.get(url)strhtml.e ...
- Python 获取时间戳
Python 获取时间通过 time 模块 如下代码,是通过获取当前的时间,按照格式输出 Python默认获取当前的时间返回的都是时间的元组,下面是元组的,字符串时间的一个转换输出 # -*- cod ...
- 金融量化分析-python量化分析系列之---使用python获取股票历史数据和实时分笔数据
财经数据接口包tushare的使用(一) Tushare是一款开源免费的金融数据接口包,可以用于获取股票的历史数据.年度季度报表数据.实时分笔数据.历史分笔数据,本文对tushare的用法,已经存在的 ...
- python获取Excel数据
Python中一般使用xlrd(excel read)来读取Excel文件,使用xlwt(excel write)来生成Excel文件(可以控制Excel中单元格的格式),需要注意的是,用xlrd读取 ...
- HTTP协议与使用Python获取数据并写入MySQL
一.Http协议 二.Https协议 三.使用Python获取数据 (1)urlib (2)GET请求 (3)POST请求 四.爬取豆瓣电影实战 1.思路 (1)在浏览器中输入https://movi ...
- Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据
Python Elasticsearch api 描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下 ...
随机推荐
- lua一些特殊函数说明
setclLvalue(L, L->top, cl); 这是个宏展开是这样: ((L->top)->value_).gc = obj2gco(cl); //top valud gc ...
- webshell文件下载器
拥有webshell的服务器可以ping通主机A,这就表明webshell可以向主机A post一些数据. 在主机A上开启一个接受文件的http服务,在webshell中使用文件上传命令进行上传. 主 ...
- Java 过滤特殊字符的 正则表达式
Java正则表达式学习: 因为正则表达式是一个很庞杂的体系,此例仅举些入门的概念,更多的请参阅相关书籍及自行摸索. \\ 反斜杠 \t 间隔 ('\u0009') \n 换行 ('\u000A') \ ...
- git学习笔记(四)—— 分支管理
一.创建与合并分支 git branch //查看分支 git branch <name> //创建分支 git checkout <name> //切换分支 git chec ...
- Android MD5校验码的生成与算法实现
在Java中,java.security.MessageDigest (rt.jar中)已经定义了 MD5 的计算,所以我们只需要简单地调用即可得到 MD5 的128 位整数.然后将此 128 位计 ...
- 开源项目mark
1. Apache的开源软件列表 http://www.oschina.net/project/apache 2. Java开源Apache项目 http://www.open-open.com/56 ...
- Groovy 学习手册(1)
1. 需要安装的软件 Java / Groovy 对应 Java 和 Groovy,你需要安装以下软件: Java JDK,例如 JDK 8 IDE,例如 Eclipse,NetBeans 8 Gro ...
- Springboot使用junit
1. 首先要下载配套的spring-boot-starter-test包,注意版本要对应. compile("org.springframework.boot:spring-boot-sta ...
- C#winform实现跑马灯
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- [转]BSIM Parameters
Name Alias Description MOSFET LevelL LV1 Channel Length (L)This is also the effective channel length ...