Sign in

1. make sure the following was installed

sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git
sudo apt install pyenv
or
curl https://pyenv.run | bash
or
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
pyenv versionspyenv install -v 3.7.9pyenv global 3.7.9
pipenv --python 3.7.9pipenv install <package>pipenv shell
python --version
pip install -U setuptools

# first specify string format
localFormat = “%Y-%m-%dT%H:%M:%S.000000000Z”
# construct a datetime from string
localmoment_naive = datetime.strptime('2020-09-22T01:02:03.000000000Z', localFormat)
# set timezone to utc
utcomment = localmoment_naive.replace(tzinfo=pytz.utc)
# convert time to expected timezone
localDatetime = utcomment.astimezone(pytz.timezone("America/Toronto"))
# show it
localDatetime

import pandas_datareader as pdr# Load the Data
datadf = pdr.DataReader(“MSFT”,
start=’2019–1–1',
end=’2020–12–31',
data_source=’yahoo’)[[‘Open’, ‘High’, ‘Low’, ‘Close’, ‘Volume’]]
data = bt.feeds.PandasData(dataname=datadf)
cerebro.adddata(data) # First add the original data — smaller timeframe
# this is key function to resample data to weekly
datadf1 = datadf.resample(‘W’, label=’left’).agg({
‘Open’: ‘first’,
‘High’: ‘max’,
‘Low’: ‘min’,
‘Close’: ‘last’,
‘Volume’: ‘sum’
})
datadf1.reset_index(level=0, inplace=True)
# have to add 1 day to each ‘Date’, tried many ways, only this works.
datadf1[‘Date’] = pd.to_datetime(datadf1[‘Date’]).apply(pd.DateOffset(1))
datadf1 = datadf1.set_index(‘Date’)
# end of resample to weekly



foo=> SET TIMEZONE TO 'Japan';
SET
foo=> SELECT '2011-01-01 00:00:00'::TIMESTAMP;
timestamp
---------------------
2011-01-01 00:00:00
(1 row)

foo=> SELECT '2011-01-01 00:00:00'::TIMESTAMP WITH TIME ZONE;
timestamptz
------------------------
2011-01-01 00:00:00+09
(1 row)

foo=> SELECT '2011-01-01 00:00:00+03'::TIMESTAMP;
timestamp
---------------------
2011-01-01 00:00:00
(1 row)

foo=> SELECT '2011-01-01 00:00:00+03'::TIMESTAMP WITH TIME ZONE;
timestamptz
------------------------
2011-01-01 06:00:00+09
(1 row)

foo=> SET TIMEZONE TO 'Australia/Melbourne';
SET
foo=> SELECT '2011-01-01 00:00:00'::TIMESTAMP;
timestamp
---------------------
2011-01-01 00:00:00
(1 row)

foo=> SELECT '2011-01-01 00:00:00'::TIMESTAMP WITH TIME ZONE;
timestamptz
------------------------
2011-01-01 00:00:00+11
(1 row)

foo=> SELECT '2011-01-01 00:00:00+03'::TIMESTAMP;
timestamp
---------------------
2011-01-01 00:00:00
(1 row)

foo=> SELECT '2011-01-01 00:00:00+03'::TIMESTAMP WITH TIME ZONE;
timestamptz
------------------------
2011-01-01 08:00:00+11
(1 row)

import iso8601
import pytz
_date_obj=iso8601.parse_date("2018-09-07T04:57:58.050-07:00")
_date_utc=_date_obj.astimezone(pytz.timezone('America/Toronto'))
_date_utc_zformat=_date_utc.strftime('%Y-%m-%dT%H:%M:%SZ')
print(_date_utc_zformat)

TimeZone timeZone = TimeZone.getTimeZone("yourTimeZone"); // e.g. "Europe/Rome"
TimeZone.setDefault(timeZone);

DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss")
.withZone(ZoneId.of("America/Toronto"));
Instant instant = Instant.parse( "2020–04–05T21:00:00.000000000Z" );
ZoneId z = ZoneId.of( "America/Toronto" );
ZonedDateTime zdt = instant.atZone( z );
System.out.io.print(zdt.format((formatter)));
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss")
.withZone(ZoneId.of("America/Toronto"));
Instant instant = Instant.ofEpochMilli(Long.parseLong("1586379600")*1000);
ZoneId z = ZoneId.of( "America/Toronto" );
ZonedDateTime zdt = instant.atZone( z );
System.out.io.print(zdt.format((formatter)));


joel

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store