Commit faff7237 authored by Tim Graham's avatar Tim Graham
Browse files

[1.6.x] Updated timezone docs to use timezone.now()

Thanks James Cleveland for the report and Aymeric for suggesting
the solution.

Backport of da599022 from master
parent e4b2bea7
Loading
Loading
Loading
Loading
+6 −13
Original line number Diff line number Diff line
@@ -78,20 +78,13 @@ the current time, you would write::

    now = datetime.datetime.now()

When time zone support is enabled, Django uses time-zone-aware datetime
objects. If your code creates datetime objects, they should be aware too. In
this mode, the example above becomes::
When time zone support is enabled (:setting:`USE_TZ=True <USE_TZ>`), Django uses
time-zone-aware datetime objects. If your code creates datetime objects, they
should be aware too. In this mode, the example above becomes::

    import datetime
    from django.utils.timezone import utc

    now = datetime.datetime.utcnow().replace(tzinfo=utc)

.. note::
    from django.utils import timezone

    :mod:`django.utils.timezone` provides a
    :func:`~django.utils.timezone.now()` function that returns a naive or
    aware datetime object according to the value of :setting:`USE_TZ`.
    now = timezone.now()

.. warning::

@@ -555,7 +548,7 @@ Troubleshooting
       >>> import datetime
       >>> from django.utils import timezone
       >>> naive = datetime.datetime.utcnow()
       >>> aware = naive.replace(tzinfo=timezone.utc)
       >>> aware = timezone.now()
       >>> naive == aware
       Traceback (most recent call last):
       ...