0

I want to show user timezone on my django application. The database is on postgresql server. With the configuration below can not reach my goal.

Django side:


TIME_ZONE = 'UTC'

USE_L10N = True

USE_TZ = True

This is my date field:

created = models.DateTimeField(auto_now =True)

Postgres side: In my database, the field "created" seems to be aware of timezone:

\d my_table;
Column      |           Type  
created     | timestamp with time zone 

Here is a sample of data stored in this field. it stores the user's timezone and not the UTC:

select created from my_table;
            created
-------------------------------
 2019-02-03 10:05:40.462164+02

Additionnel info:
- pytz is installed.
- my django app shows the UTC time.

My question: How can I show the timezone to the user? Do you see that there is something wrong with my configuration?

Thanks a lot in advance.

3
  • You need to change your Postgresql timezone to utccommand ALTER USER User_Name SET TimeZone TO 'utc'; and restart postgresql sudo service postgresql restart Commented Apr 5, 2019 at 9:26
  • Possible duplicate of PostgreSQL saving date in 'Local time zone' while i set it to 'UTC' with Django Commented Apr 5, 2019 at 9:30
  • No it seems that this solution does not work Commented Apr 5, 2019 at 9:34

1 Answer 1

2

You need change Postgresql timezone to UTC. command:

ALTER USER User_Name SET TimeZone TO 'utc';

And restart the postgres service:

sudo service postgresql restart

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.