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
| Name | Type | Description |
|---|---|---|
| value | any | The value to be checked and potentially converted, typically a datetime object. |
| use_tz | boolean = None | A flag to explicitly enable or disable timezone conversion, overriding the global settings.USE_TZ configuration. |
Returns
| Type | Description |
|---|---|
datetime | The converted datetime object in the local timezone if conversion criteria are met; otherwise, the original value. |