From the database, I query out the created\_date and put in the template:

[![enter image description here](https://i.stack.imgur.com/vCWhC.jpg)](https://i.stack.imgur.com/vCWhC.jpg)

You see, it is UTC time, how can I in the template shows the +8 timezone time?

I tried use the custom template-filter to change, but failed:

```
from django import template
from django.template.defaultfilters import stringfilter
import datetime, time

register = template.Library()

### function

def utc2local(utc_st):
   """UTC时间转本地时间（+8:00)"""
   now_stamp = time.time()
   local_time = datetime.datetime.fromtimestamp(now_stamp)
   utc_time = datetime.datetime.utcfromtimestamp(now_stamp)
   offset = local_time - utc_time
   local_st = utc_st + offset

   return local_st

@register.filter
def convert_utc_to_shanghai(value):
    """
    UTC->Shanghai
    :param value:
    :return:
    """

    local_time = utc2local(value)

    print local_time.strftime("% Y - % m - % d % H: % M: % S")

    return local_time.strftime

```