Skip to main content

template_localtime

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.

def template_localtime(
value: any,
use_tz: boolean = None
) - > datetime

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.

Parameters

NameTypeDescription
valueanyThe value to be checked and potentially converted, typically a datetime object.
use_tzboolean = NoneA flag to explicitly enable or disable timezone conversion, overriding the global settings.USE_TZ configuration.

Returns

TypeDescription
datetimeThe converted datetime object in the local timezone if conversion criteria are met; otherwise, the original value.