Chobeat
Chobeat

Reputation: 3535

DatetimeProperty to Javascript time

I'm a bit confused by how i'm supposed to pass a datetime value from python to javascript.

I have my value stored in the datastore, i retrieve it and then i do something like:

<div class="notification" date="{{notification.date}}">
...
</div>

and this is the HTML

<div class="notification" date="2012-09-21 14:47:54.313000">
...
</div>

Then what?

I've found a tons of different suggestions but almost everytime i got errors because the DatetimeProperty, apparently is different from datetime.

Can Javascript parse that date? If so, how? Otherwise, how should i pass that value?

Upvotes: 2

Views: 188

Answers (2)

Paul Collingwood
Paul Collingwood

Reputation: 9116

If jinja2, perhaps a custom filter first?

def datetimeformat(value, format='%H:%M / %d-%m-%Y'):
return value.strftime(format)

http://jinja.pocoo.org/docs/api/#custom-filters

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599480

new Date("2012-09-21 14:47:54.313000")

Works for me.

Upvotes: 1

Related Questions