Log*_*ran 3 timezone alpha-vantage
我可以更改 Alpha Vantage API 结果中的时区吗?这是输出的示例。目前是美国东部时间。我想把它放在 IST 中。
'Meta Data': {
'1. Information': 'Intraday (1min) open, high, low, close prices and volume',
'2. Symbol': 'BSE:------',
'3. Last Refreshed': '2019-11-01',
'4. Output Size': 'Compact',
'5. Time Zone': 'US/Eastern
}
'Time Series (1min)': {
'2019-11-01 00:08:59': {
'1. open': '70.7500',
'2. high': '70.7500',
'3. low': '70.7500',
'4. close': '70.7500',
'5. volume': '0'
},
Run Code Online (Sandbox Code Playgroud)
欢迎来到 StackOverflow!
目前,返回的时区是您从 API 收到的唯一时区。但是,如果您使用 python 脚本提取数据。您随时可以将其转换为您选择的时区。
from alpha_vantage.timeseries import TimeSeries
from datetime import datetime
import pytz
ts = TimeSeries()
data, meta_data = ts.get_daily('TSLA')
format = '%Y-%m-%d %H:%M:%S'
datetime = datetime.strptime(meta_data['3. Last Refreshed'], format)
old_timezone = pytz.timezone(meta_data['5. Time Zone'])
new_timezone = pytz.timezone("Asia/Calcutta")
# returns datetime in the new timezone
my_timestamp_in_new_timezone = old_timezone.localize(datetime).astimezone(new_timezone)
print(my_timestamp_in_new_timezone.strftime(format))
Run Code Online (Sandbox Code Playgroud)
您可以运行一个方法,在提取数据时将所有时间转换为您想要的任何时区
| 归档时间: |
|
| 查看次数: |
3092 次 |
| 最近记录: |