If I run this where vote.created_on is a python datetime:
import calendar
created_on_timestamp = calendar.timegm(vote.created_on.timetuple())*1000
created_on_timestamp = str(created_on_timestamp)
created_on_timestamp will be printed with encapsulating tick marks (‘). If I do int() or something like that, I’ll get something like 1240832864000L which isn’t a number as far as JavaScript is concerned (which is where I need to use these datetimes).
Does anybody know the best way to handle this situation? Should I cast the long as a string and strip the tick marks? That seems crazy.
=== Edited Addendum ===
The larger problem was that Django was converting ” into it’s HTML encoded equivalent &39; (or similar). The best way to deal with this is to convert the long into a string and when the template parses the string, use {{ created_on_timestamp|safe }} to render the quote marks as quote marks.
The L only shows up when you trigger the object’s
__repr__When and how are you sending this data to JavaScript? If you send it as JSON, you shouldn’t have to worry about long literals or how Python displays its objects within Python.