Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  167] [ 5]  / answers: 1 / hits: 20501  / 14 Years ago, tue, february 22, 2011, 12:00:00

What would be the easy way of achieving such below? selected_date comes from django context as a python date :



<script type=text/javascript>
var selected_year = {{ selected_date|date:Y }}
var selected_month = {{ selected_date|date:m }} - 1;
var selected_day = {{ selected_date|date:d}}
var selected_date = new Date(selected_year, selected_month, selected_day);
alert(selected_date);
</script>

More From » django

 Answers
9

I've had a lot of success with the isoformat function in python:



var selected_date = new Date({{ selected_date.isoformat }})

[#93637] Saturday, February 19, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mikael

Total Points: 73
Total Questions: 115
Total Answers: 86

Location: Central African Republic
Member since Mon, Aug 10, 2020
4 Years ago
;