I am using linux aws machine and there is a timezone difference when I do datetime.datetime.now. So I have tried this method to overcome the timezone error
format = "%Y-%m-%d %H:%M:%S %Z%z"
current_date = datetime.datetime.now()
now_asia = current_date.astimezone(timezone('Asia/Kolkata'))
print(now_asia.strftime(format))
when I do my window machine I didnt get any error. The same lines when I use in my linux machine I am getting "ValueError: astimezone() cannot be applied to a naive datetime"
To debug this I tried the methods which is mentioned in this link pytz and astimezone() cannot be applied to a naive datetime
when I tried the first answer I am not getting any error but the timezone is not converted. when I tried the second answer I am getting an error 'AttributeError: 'module' object has no attribute 'utcnow'
I tried this
>>>loc_date = local_tz.localize(current_date)
>>> loc_date
datetime.datetime(2020, 4, 6, 7, 23, 36, 702645, tzinfo=<DstTzInfo 'Asia/Kolkata' IST+5:30:00 STD>)
>>> loc_date.strftime(format)
'2020-04-06 07:23:36 IST+05:30'
I am getting this ,so according to indian time if we add 5:30 it will be correct. How should i do it.