Tuesday, November 30, 2010

Re: Django timestamp to Javascript timestamp

You can use this format

{{date|date:"Y/m/d H:i:s"}}
d = new Date("2010/11/30 09:58:25");

The problem with ms is that Javascripts accepts only two decimals so
if you want to use miliseconds you can do something like this:

function to_datetime(datetime){
// from python >>> datetime.now().strftime("%d/%m/%Y %H:%M:%S.%f")
//transform datetime= "dd/mm/YYYY HH:MM:SS.ms" string to Date()
try{
datetime.getTime();}
catch(err){

var d_t = datetime.split(/[/\s:.]/);
var dmyHMS = new Array;
for(var i in d_t){
dmyHMS.push(parseFloat(d_t[i]));
}
var datetime = new Date(dmyHMS[2],
dmyHMS[1]-1,
dmyHMS[0],
dmyHMS[3],
dmyHMS[4],
dmyHMS[5],
dmyHMS[6]) ; <= you can truncate to two
decimals from python (%.2f) %value
}
return datetime


Now i'm working in a graph time based in canvas, tell me if you are
interested, and i'll send you the file

--
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