Skip to content

Instantly share code, notes, and snippets.

View blackjid's full-sized avatar
🎹

Juan Ignacio Donoso blackjid

🎹
View GitHub Profile
@blackjid
blackjid / dateDjango.js
Created April 19, 2012 16:53
Create a Javascript date object with the time synced with the server time. The code must be processed in the server.
// Django template
(function(){
var _date = new Date();
date = {
gmtOffset: {% now "Z" %},
offset: {% now "U" %} - Math.round(_date.getTime() / 1000),
now: function(unix){
if(unix)
return Math.round(_date.getTime() / 1000) + this.offset + _date.getTimezoneOffset()*60*1000 + this.gmtOffset*1000;
return new Date(((Math.round(_date.getTime() / 1000) + this.offset)*1000) + _date.getTimezoneOffset()*60*1000 + this.gmtOffset*1000);