Settings environment timezones django postgres linux

0

Good morning, everyone.

I have a site (Django) on a linux hosting service with Postgre SQL bank that is in New Jersey (USA). Users are in Brazil, so I have a timezone difference.

I'm pretty sure this is a silly thing, with an adjustment I solve everything, but I'm confused because the changes and tests I've done have given incorrect results.

First I'll post the settings of the environments.

Linux Server (USA):

$cat /etc/timezone
Etc/UTC

Postgres Console (USA):

postgres=# show timezone;
UTC

Django settings.py (USA):

TIME_ZONE = 'America/Sao_Paulo'
USE_TZ = True

But now we're going to the results.

Here in Brazil they are:

  

10: 07h

There on the Linux (USA) server:

  

12:07:52 UTC

Here for me it's already wrong, there are 3 hours and difference, 2 hours with daylight saving time?

No POSTGRES:

select now();
2018-01-16 12:07:36.967415+00

I have a template called COLLECT that has a field that is called DATA_DELECTION.

data_leitura = models.DateTimeField(null=True)

So I just put a record in this table with the time of 10:07:16. I create the datetime that I assign to the COLLATE model. Reading_day is this:

br_tz = timezone('America/Sao_Paulo')
coleta.data_leitura = datetime(2018, 01, 16, 10, 07, 16, tzinfo=br_tz)

I accessed the linux console (NJ) in postgres and gave a select:

SELECT data_leitura FROM coleta;
2018-01-16 15:13:16+00

The value displayed on the web page for the customer here in Brazil is:

  

15:13:16

Before you did not have the line br_tz = timezone ('America / Sao_Paulo') Then a NAIVE DATETIME message appeared and the time was wrong too!

I'm trying to change every setting and it always gets worse yet, so there are 2 wrong factors to fix. It's my first experience with these environments and frameworks.

What should I change? suggestions? Thank you in advance for the help of the community!

    
asked by anonymous 16.01.2018 / 14:09

1 answer

0

You can set up an environment variable called TIMEZONE , which tells the database the region in which the client is connected to the server, so the server knows how to properly convert the hours:

SET TIMEZONE = 'America/Sao_Paulo';
SELECT NOW();
    
16.01.2018 / 14:59