timezone

Convert datetime.datetime from UTC to CEST one hour to less

Convert datetime.datetime from UTC to CEST one hour to less Question: If I run the following code I convert the datetime.datetime from utc to cest, but it does not work right. Correct would be if it would change from 21:29 to 23:29 because the time difference is 2 hours from_zone = tz.gettz(‘UTC’) to_zone = tz.gettz(‘CEST’) …

Total answers: 1

How to get current time in india in python

How to get current time in india in python Question: How would I get the current timestamp in python of India? I tried time.ctime() and datetime.utcnow() also datetime.now() but they all return a different time than here it is in india. The codes above return the time that not match the current time on my …

Total answers: 3

Creating pandas DatetimeIndex in Dataframe from DST aware datetime objects

Creating pandas DatetimeIndex in Dataframe from DST aware datetime objects Question: From an online API I gather a series of data points, each with a value and an ISO timestamp. Unfortunately I need to loop over them, so I store them in a temporary dict and then create a pandas dataframe from that and set …

Total answers: 3

How can I force pytz to use currently standard timezones?

How can I force pytz to use currently standard timezones? Question: Consider the following: from datetime import datetime import pytz new_years_in_new_york = datetime( year=2020, month=1, day=1, hour=0, minute=0, tzinfo = pytz.timezone(‘US/Eastern’)) I now I have a datetime object representing January 1, midnight, in New York. Oddly, if I use pytz to convert this to UTC, …

Total answers: 1

python timezone problem with the same timezone

python timezone problem with the same timezone Question: Why I get different result timezone in the one file with the almost same datetime constructions? print(datetime.datetime.now(pytz.timezone(‘Europe/Moscow’))) >>> 2020-05-31 12:55:04.778210+03:00 print(datetime.datetime(2020, 5, 31, 12, 54, 0, 0, pytz.timezone(‘Europe/Moscow’))) >>> 2020-05-31 12:54:00+02:30 Asked By: Real Lord || Source Answers: the problem lies within the fact that pytz uses …

Total answers: 1

How to show time value based on user's time zone using Django template tags

How to show time value based on user's time zone using Django template tags Question: I’m saving all timing to my database in ‘UTC’ time zone, but I want every user to see this value converted to his own timezone. is it possible to be used in Django? my settings.py : TIME_ZONE = ‘UTC’ USE_I18N …

Total answers: 3

Why do I get the offset 0:53 for timezone Europe/Berlin?

Why do I get the offset 0:53 for timezone Europe/Berlin? Question: Example Code from datetime import datetime, timezone import pytz tzstring = ‘Europe/Berlin’ t1 = datetime(2016, 6, 16, 2, 0, tzinfo=pytz.timezone(tzstring)) t2 = datetime(2016, 6, 16, 2, 0, tzinfo=timezone.utc).astimezone(pytz.timezone(tzstring)) Observed print(t1): 2016-06-16 02:00:00+00:53 print(t2): 2016-06-16 04:00:00+02:00 Expected print(t1): 2016-06-16 04:00:00+02:00 # does not match expectation …

Total answers: 1

How to remove timezone from a Timestamp column in a pandas dataframe

How to remove timezone from a Timestamp column in a pandas dataframe Question: I read Pandas change timezone for forex DataFrame but I’d like to make the time column of my dataframe timezone naive for interoperability with an sqlite3 database. The data in my pandas dataframe is already converted to UTC data, but I do …

Total answers: 4

flask: convert utc time to user's local time

flask: convert utc time to user's local time Question: I’m trying to convert a UTC time to the appropriate local time in a flask application. I’m wondering if I can detect the user’s timezone and dynamically set it. This is my code so far which works for everyone in the US/Pacific timezone only (datetimefilter pulled …

Total answers: 2

python schedule jobs with different timezones

python schedule jobs with different timezones Question: I want to schedule a python function to run everyday at a certain time for a list of customers with different timezones. This is basically what I want to do: import schedule import time def job(text): print(“Hello ” + text) def add_job(user_tz, time, text): schedule.every().day.at(time).do(job(text)) # the above …

Total answers: 2