Module timezone
Timezone-related classes and functions.
source linkClasses
Functions
▶ def activate(timezone) Set the time zone for the current thread.
The ``timezone`` argument must be an instance of a tzinfo subclass or a
time zone name.
▶ def deactivate() Unset the time zone for the current thread.
Django will then use the time zone defined by settings.TIME_ZONE.
▶ def get_default_timezone() @functools.lru_cache() Return the default time zone as a tzinfo instance.
@functools.lru_cache()
def get_default_timezone()
This is the time zone defined by settings.TIME_ZONE.
Reexports
▶ def is_aware(value) Determine if a given datetime.datetime is aware.
The concept is defined in Python's docs:
https://docs.python.org/library/datetime.html#datetime.tzinfo
Assuming value.tzinfo is either None or a proper datetime.tzinfo,
value.utcoffset() implements the appropriate logic.
Reexports
▶ def is_naive(value) Determine if a given datetime.datetime is naive.
The concept is defined in Python's docs:
https://docs.python.org/library/datetime.html#datetime.tzinfo
Assuming value.tzinfo is either None or a proper datetime.tzinfo,
value.utcoffset() implements the appropriate logic.
Reexports
▶ def localdate(value=None, timezone=None) Convert an aware datetime to local time and return the value's date.
Only aware datetimes are allowed. When value is omitted, it defaults to
now().
Local time is defined by the current time zone, unless another time zone is
specified.
▶ def localtime(value=None, timezone=None) Convert an aware datetime.datetime to local time.
Only aware datetimes are allowed. When value is omitted, it defaults to
now().
Local time is defined by the current time zone, unless another time zone
is specified.
▶ def make_aware(value, timezone=None, is_dst=None) Make a naive datetime.datetime in a given time zone aware.
▷ def make_naive(value, timezone=None) Make an aware datetime.datetime naive in a given time zone.
▶ def now() Return an aware or naive datetime.datetime, depending on settings.USE_TZ.
▶ def template_localtime(value, use_tz=None) Check if value is a datetime and converts it to local time if necessary.
If use_tz is provided and is not None, that will force the value to
be converted (or not), overriding the value of settings.USE_TZ.
This function is designed for use by the template engine.
Reexports