python - How does Django Timezone Work? -


so, in settings have following:

language_code = 'en-us'  use_i18n = true  use_l10n = true  use_tz = true  time_zone = 'europe/copenhagen' 

however, when issue:

timezone.now() datetime.datetime(2015, 9, 26, 8, 47, 15, 862729, tzinfo=<utc>) 

and time 2 hours late.

i reading documentation , see method calls datetime.datetime() , information there correct. see output based on variable time_zone, set current location. shouldn't timezone.now() correct time_zone time then?

another question: datetime.datetime() gets information server?

  1. yes, gets information machine runs code.
  2. no, doesn't give local time. no, doesn't use timezone settings (doc ref, code ref). uses utc time (europe/copenhagen utc+2).
  3. if want local datetime object should make naive:

    timezone.make_naive(timezone.now(), timezone.get_current_timezone())   

Comments