pytz

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

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 pytz timezone function returns a timezone that is off by 9 minutes

Python pytz timezone function returns a timezone that is off by 9 minutes Question: For some reason which I haven’t been able to figure out yet, from the the following code: >>> from pytz import timezone >>> timezone(‘America/Chicago’) I get: <DstTzInfo ‘America/Chicago’ LMT-1 day, 18:09:00 STD> When, I assume, I should get: <DstTzInfo ‘America/Chicago’ LMT-1 …

Total answers: 4

Get system local timezone in python

Get system local timezone in python Question: Seems strange, but I cannot find an easy way to find the local timezone using pandas/pytz in Python. I can do: >>> pd.Timestamp(‘now’, tz=’utc’).isoformat() Out[47]: ‘2016-01-28T09:36:35.604000+00:00’ >>> pd.Timestamp(‘now’).isoformat() Out[48]: ‘2016-01-28T10:36:41.830000’ >>> pd.Timestamp(‘now’).tz_localize(‘utc’) – pd.Timestamp(‘now’, tz=’utc’) Out[49]: Timedelta(‘0 days 01:00:00’) Which will give me the timezone, but this is …

Total answers: 5

Import pytz into AWS lambda function

Import pytz into AWS lambda function Question: I’m writing a lambda function that works with datetimes and trying to import pytz so I can have timezone be accounted for when comparing. import boto3 import pytz from datetime import timedelta, date, datetime from boto3.dynamodb.conditions import Key, Attr causes this to display {errorMessage=Unable to import module ‘lambda_function’} …

Total answers: 7

Python string to Django timezone (aware datetime)

Python string to Django timezone (aware datetime) Question: TL;DR; How to convert 2016-01-01 to Django timezone? Full version: I receive a query string parameter from a form and I wanna get that string and use it as a datetime filter in Django. The problem is that when I convert the string to a datetime, it’s …

Total answers: 3

How do you convert a datetime/timestamp from one timezone to another timezone?

How do you convert a datetime/timestamp from one timezone to another timezone? Question: Specifically, given the timezone of my server (system time perspective) and a timezone input, how do I calculate the system time as if it were in that new timezone (regardless of daylight savings, etc)? import datetime current_time = datetime.datetime.now() #system time server_timezone …

Total answers: 4

How to convert datetime.date.today() to UTC time?

How to convert datetime.date.today() to UTC time? Question: How to make sure the datetime.date.today() is converted to UTC time? This is my code so far: #today : 2014-12-21 today = datetime.date.today() #1900-01-01 16:00:00+00:00 timeformat = datetime.datetime.strptime(’16:00′, ‘%H:%M’).replace(tzinfo=pytz.utc) #combine today and timeformat 2014-12-21 16:00:00 now = datetime.datetime.combine(u, timeformat.time()) str_now = now.strftime(“%Y-%m-%d %H:%M:%S”) Asked By: user2492364 || …

Total answers: 2

pytz – Converting UTC and timezone to local time

pytz – Converting UTC and timezone to local time Question: I have a datetime in utc time zone, for example: utc_time = datetime.datetime.utcnow() And a pytz timezone object: tz = timezone(‘America/St_Johns’) What is the proper way to convert utc_time to the given timezone? Asked By: Tzach || Source Answers: May I recommend to use arrow? …

Total answers: 6

unexpected results converting timezones in python

unexpected results converting timezones in python Question: I’m trying to understand why I’m getting these results when converting time zones to UTC: In [74]: d1 = datetime(2007, 12, 5, 6, 30,tzinfo=pytz.timezone(‘US/Pacific’)) In [75]: d1 Out[75]: datetime.datetime(2007, 12, 5, 6, 30, tzinfo=<DstTzInfo ‘US/Pacific’ LMT-1 day, **16:07:00 STD**>) In [76]: d1.astimezone(pytz.utc) Out[76]: datetime.datetime(2007, 12, 5, 14, 23, …

Total answers: 5