I'm trying to change the timezone of UTC to America/Sao Paulo, but I'm getting this error:
TypeError: replace() takes no keyword arguments
This is my code:
import pytz
local_tz = pytz.timezone('America/Sao_Paulo')
local_dt = candles[0]['time'].replace(tzinfo=pytz.utc).astimezone(local_tz)
Candle time is:
>>> candles[0]['time']
u'2017-08-03T00:03:00.000000Z'
How can I fix this?
You need to convert your candles[0]['time']
which is a unicode string to datetime
object.
Here is an example:
import datetime, pytz
a = u'2017-08-03T00:03:00.000000Z'
local_tz = pytz.timezone('America/Sao_Paulo')
local_dt = datetime.datetime.strptime(a, '%Y-%m-%dT%H:%M:%S.000000Z').replace(tzinfo=pytz.utc).astimezone(local_tz)
print local_dt
Output:
2017-08-02 21:03:00-03:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With