Reputation: 337
I have a Django API/PostgreSql project, where i try to store the datetime in UTC format, which later i will convert to a correct timezone in the front end with angular.
My current settings are:
USE_TZ = True
TIME_ZONE = 'US/Eastern'
I was first using UTC, but for some reason the datetime was stored as +1 hour, so i set the time zone to my servers time zone
Model:
date = models.DateTimeField(default = timezone.now())
But still when i retrieve the inserted record, the time is -3 minutes late.
While when i use the code bellow, it stores a correct time:
date = models.DateTimeField(auto_now_add=True)
Am i missing something in the configuration ? What TIME_ZONE should i use, server location time_zone, or it has to do with the servers time setup ?
Upvotes: 2
Views: 627
Reputation: 337
The issue is fixed, i dont know why but when im using:
date = models.DateTimeField(default = timezone.now()) # note: .now() with parenthesizes
The time gets stuck, at the time when the server started up.
The fix use:
date = models.DateTimeField(default = timezone.now) # without ()
Im on Django 1.6.5
Upvotes: 1