Reputation: 723
I've a problem that Django on AWS EC2 Ubuntu 12.04 server using this the following view returns UTC timestamp:
import time
from django.utils.datetime_safe import datetime
def currentTime(request):
return HttpResponse(json.dumps({"time": int(time.mktime(datetime.now().timetuple())) }), mimetype="application/json")
1370604628 at the time of writing. Ubuntu is set to EDT timezone and Django's settings.py is set to "America/New_York". What's even stranger Javascript is returning UTC timezone when using new Date();
My USE_TZ is set to False, but I've tried setting it to True without success.
The server is nginx and it's proxying to uWSGI. Is there anyone who knows how to resolve this issue? Or another way to sync time between client JS and django?
Upvotes: 0
Views: 273
Reputation: 241450
I'm not familiar with the specifics of Django, but I can tell you that in general, integer time stamps, such as 1370604628
are always in UTC.
The value you have from Python is number of seconds since 1/1/1970 UTC. In JavaScript, the number would be represented in milliseconds, so you have to multiply by 1000. But the zero line is at the same point - Jan 1st, 1970 UTC.
It does not matter what any of your time zone settings are. These values are always in UTC. If you want time zone information to be incorporated, then you have to use a string representation rather than an integer.
Upvotes: 1