Monday, November 29, 2010

Re: Django timestamp to Javascript timestamp

I found it easiest to use the javascript date constructor with a date string. Just have Django output the date in whatever time zone you want it displayed to the user:
var d=new Date("November 29, 2010 9:22:00");
Unfortunately Django's default Date display, the ISO standard, prints a string that cannot be read by javascript, so:
var d=new Date("{{ mymodel.date }}");
will not work out of the box.

If you change the DATETIME_FORMAT setting to "r", some other standard, the above will work.

Also...you are using a DateTimeField, not a DateField, right?




On Mon, Nov 29, 2010 at 8:47 PM, Bill Freeman <ke1g.nh@gmail.com> wrote:
Unix (and python) timestamps are also from the beginning of Jan 1, 1970, but are
in seconds, so you might think that multiplying by 1000 would be enough.  But
unix timestamps (and, presumably, their emulation on Windows) are in GMT, while
JavaScript, if memory serves, uses the browser's local machine's timezone.  JS
data/time manipulations have enough stuff to fix this, but you have to
work a bit,
including considering whether you are in daylight savings time, etc..

Bill

On Mon, Nov 29, 2010 at 1:16 PM, Matt  Thompson <thompsonson@gmail.com> wrote:
> Hello guys and girls,
>
> I'm looking to use Flot to graph some data I have in my Django app.
> I'd like to graph a time based query and need to get the time is
> Javascript format (milliseconds since 01/01/1970).
>
> I can get it into seconds\unix format, this is seconds since
> 01/01/1970, but not milliseconds.
>
> Can anyone help?
>
> Thanks,
> Matt
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment