pytz

pytz timezone tags to adjust date printed in templates

那年仲夏 提交于 2019-12-10 15:27:14
问题 Inside my app I use normal datetime objects. In my template: {% load tz %} {{datetimeobject|timezone:"Europe/Paris"}} {% timezone "Europe/Paris" %} {{datetimeobject}} {% endtimezone %} This prints something like this: Dec. 5, 2012, 4 p.m. Dec. 5, 2012, 3 p.m. So the timezone filter adjusts the date but timezone tag DOES NOT. Why is that? And how I can use tag properly? My goal is to adjusts all datetimeobjects in whole template without adding filter to every datetimeobject printed in template

Changing timezone on an existing Django project

隐身守侯 提交于 2019-12-10 13:43:44
问题 Like an idiot, I completely overlooked the timezone setting when I first built an application that collects datetime data. It wasn't an issue then because all I was doing was "time-since" style comparisons and ordering. Now I need to do full reports that show the actual datetime and of course, they're all stored at America/Chicago (the ridiculous Django default). So yes. I've got a medium sized database full of these dates that are incorrect. I want to change settings.TIME_ZONE to 'UTC' but

Import pytz into AWS lambda function

◇◆丶佛笑我妖孽 提交于 2019-12-10 13:29:00
问题 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'} but when I remove import pytz the function fires (it just doesn't work properly without timezone info) 回答1: You need to install the pytz package so it's

Issue with python/pytz Converting from local timezone to UTC then back

[亡魂溺海] 提交于 2019-12-09 17:56:15
问题 I have a requirement to convert a date from a local time stamp to UTC then back to the local time stamp. Strangely, when converting back to the local from UTC python decides it is PDT instead of the original PST so the post converted date has gained an hour. Can someone explain to me what is going on or what I am doing wrong? from datetime import datetime from pytz import timezone import pytz DATE_FORMAT = '%Y-%m-%d %H:%M:%S %Z%z' def print_formatted(dt): formatted_date = dt.strftime(DATE

Python - From DST-adjusted local time to UTC

梦想与她 提交于 2019-12-09 11:20:29
问题 A specific bank has branches in all major cities in the world. They all open at 10:00 AM local time. If within a timezone that uses DST, then of course the local opening time also follows the DST-adjusted time. So how do I go from the local time to the utc time. What I need is a function to_utc(localdt, tz) like this: Arguments: localdt: localtime, as naive datetime object, DST-adjusted tz: timezone in the TZ-format, e.g. 'Europe/Berlin' Returns: datetime object, in UTC, timezone-aware EDIT:

pytz: return Olson Timezone name from only a GMT Offset

守給你的承諾、 提交于 2019-12-08 22:29:34
问题 I have a legacy application i'm going to need to supplement some data with. Currently, we have a DB table storing US (and its territories) zip codes, along with a GMT Offset, and a flag showing if that Zipcode uses daylight savings time. This was downloaded from some free provider, which I can't find the source to right now. I now need to supplement this table with the full Olson name (e.g. America/New York ) of each zipcode because that seems to be the only good way to convert a given date

Why does pytz correctly adjust time & offset when crossing TZ & DST boundaries but not the TZ name?

走远了吗. 提交于 2019-12-08 02:20:06
问题 I have reviewed several pytz -related questions here, but none seems to address the exact problem I'm seeing. Following the pytz documentation, here's a loop to print the current time in multiple time zones, including time zone offset, time zone name, and whether the datetime object thinks it's DST. nowDT = datetime.datetime.now() chicagoTz = pytz.timezone('America/Chicago') chicagoDT = chicagoTz.normalize(chicagoTz.localize(nowDT)) sys.stdout.write( "%-10s %-35s %s\n" % ('Chicago', chicagoDT

How to execute a command at exact time once a day in Django?

二次信任 提交于 2019-12-07 12:48:00
问题 I am working on a Django web based project in which i need to build a application which work in the following sequence: 1) user open a page in which he need to enter a command and a time 2) Django application will execute that command at a given time on each day till user off the scheduler (by default it is True) What i am facing the problem is that : 1) How should i execute the commands on a time but on each day. To save the commands and time i created a following model in my models.py class

Why does creating a datetime with a tzinfo from pytz show a weird time offset?

烂漫一生 提交于 2019-12-07 04:10:20
问题 Can someone explain me why I do not get the same result in those? import datetime,pytz var1 = datetime.datetime(2017,10,25,20,10,50,tzinfo=pytz.timezone("Europe/Athens"))) print(var1) The output of this code is: 2017-10-25 20:10:50+01:35 import datetime,pytz var1 = datetime.datetime(2017,10,25,20,10,50) var1 = pytz.timezone("Europe/Athens").localize(var1) print(var1) The output of this code is: 2017-10-25 20:10:50+03:00 My question is why they have different timezones (1:35 and 3:00). I know

UnknownTimeZoneError when using RequestContext

自作多情 提交于 2019-12-06 16:24:45
When using Django 1.4, I am getting an UnknownTimeZoneError for America/Chicago when using RequestContext, but it works without it...any ideas? Error Message UnknownTimeZoneError at /my_proj/bad_view/ 'America/Chicago' Source # This works def good_view(request): data = {} return render_to_response('mytemplate.html', data) # This doesn't def bad_view(request): data = {} return render_to_response('mytemplate.html', data, context_instance=RequestContext(request)) If you don't care about timezone support you should add USE_TZ = False to your settings.py . If you want timezone support you should