django   87107

« earlier    

timezone - django 1.4 - can't compare offset-naive and offset-aware datetimes - Stack Overflow
Check the thorough document for detail info.

Normally, use django.utils.timezone.now to make an offset-aware current datetime

>>> from django.utils import timezone
>>> timezone.now()
datetime.datetime(2012, 5, 18, 13, 0, 49, 803031, tzinfo=<UTC>)

And django.utils.timezone.make_aware to make an offset-aware datetime

>>> timezone.make_aware(datetime.datetime.now(), timezone.get_default_timezone())
datetime.datetime(2012, 5, 18, 21, 5, 53, 266396, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>)

You could then compare both offset-aware datetimes w/o trouble.

Furthermore, you could convert offset-awared datetime to offset-naive datetime by stripping off timezone info, then it could be compared w/ normal datetime.datetime.now(), under utc.

>>> t = timezone.now() # offset-awared datetime
>>> t.astimezone(timezone.utc).replace(tzinfo=None)
datetime.datetime(2012, 5, 18, 13, 11, 30, 705324)

USE_TZ is True 'by default' (actually it's False by default, but the settings.py file generated by django-admin.py startproject set it to True), then if your DB supports timezone-aware times, values of time-related model fields would be timezone-aware. you could disable it by setting USE_TZ=False(or simply remove USE_TZ=True) in settings.
django  datetime 
12 hours ago by hbakkalbasi
bitmazk/django-influxdb-metrics
A reusable Django app that sends metrics about your project to InfluxDB.
django  app  influxdb  opensource  monitoring 
yesterday by keimlink
rafalp/Misago
A fully featured forum application standing on shoulders of Django.
django  forum  opensource  app  emberjs  api  rest 
yesterday by keimlink
rafalp/django-hbs-makemessages
Custom makemessages implementation that can extract language strings from .hbs files.
django  library  i18n  templatetag  opensource 
yesterday by keimlink
rafalp/django-ember-gettext
Ember helpers for using Django JS translation functions in Handlebars.
emberjs  javascript  i18n  templatetag  addon  opensource  django 
yesterday by keimlink
ottoyiu/django-cors-headers
A Django App that adds CORS (Cross-Origin Resource Sharing) headers to responses.
django  app  cors  ajax  opensource 
yesterday by keimlink
mtford90/silk · GitHub
Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection:
profiling  django  performance 
yesterday by zeevb

« earlier    

related tags

addon  ajax  aldjemy  allauth  angularjs  api  app  architecture  askbot  authentication  aviary-log  aws  beaglebone  beginner  benchmark  blogs  boilerplate  bootstrap  brew  cache  caching  cms  codeschool  coding  command_line  computing  cors  css  database  datetime  deployment  development  devops  diversity  documentation  drag_and_drop  ec2  education  elasticbeanstalk  elasticsearch  emberjs  environment  factory_boy  flask  forms  forum  framework  frameworks  geo  gulp  hosting  howoto  i18n  influxdb  ios  ipython  javascript  job  leaflet  library  logging  mac  metrics  microservices  migrations  minecraft  monitoring  mysql  nose  numpy  opensource  openstreetmap  osx  performance  postgresql  profiling  programming  python  raspberrypi  resource  rest  scaling  scripting  security  settings  software  sqlalchemy  sqlite  tdd  templatetag  testing  tribute  tutorial  unix  uwsgi  views  webdesign  webdev 

Copy this bookmark:



description:


tags: