Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript/python time processing fails in chrome
    text
    copied!<p>I am writing a timer web app,which records start time and stop time.It uses <code>javascript,jquery1.4.2</code> for the front end and <code>python</code> for backend code.When a start button is clicked ,start time is saved in a javascript variable.when the button is clicked again, stop time is saved in another variable.These values are passed as hidden parameters to the python code which gets the start,stop values from <code>django</code>'s <code>request</code> parameter.</p> <p>I expect the start/stop parameters values to be in the following format</p> <pre><code>"07:16:03 PM" </code></pre> <p>so that it can be parsed using <code>'%I:%M:%S %p'</code>format string. I am getting this correctly in <code>mozilla firefox</code>.But when I use <code>chrome</code>,I only get</p> <pre><code>"19:16:03" </code></pre> <p>This causes value error when I try to parse it with the above format string.</p> <pre><code>import time ... def process_input(request,...): start_time=request.POST[u'timerstarted'] ... fmtstr='%I:%M:%S %p' start_time_list = list(time.strptime(start_time,fmtstr)[3:6]) </code></pre> <p>I tried putting <code>alert('start time set as'+start_time)</code> in javascript to find what values are set in the page's hiddenfields</p> <p>With firefox ,I got</p> <pre><code>start time set as08:03:09 PM stop time set as08:03:43 PM </code></pre> <p>but with chrome</p> <pre><code>start time set as20:04:21 stop time set as20:04:32 </code></pre> <p>My knowledge of javascript,jquery is minimal.Why is the script behaving differently in these two browsers? Below is the javascript snippet</p> <pre><code>$(document).ready(function(){ var changeBtnStatus=function(){ var timebtnvalue=$('#timebtn').attr("value"); if (timebtnvalue =="start"){ ... var start_date=new Date(); var str_time=start_date.toLocaleTimeString(); var timerstartedfield =$('#timerstarted'); timerstartedfield.attr("value",str_time); alert('start time set as'+str_time); } else if (timebtnvalue=="stop"){ ... var stop_date=new Date(); var stp_time=stop_date.toLocaleTimeString(); var timerstoppedfield =$('#timerstopped'); timerstoppedfield.attr("value",stp_time); alert('stop time set as'+stp_time); } }; var timerBtnClicked=function(){ ... changeBtnStatus(); }; $('#timebtn').click(timerBtnClicked); ... } ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload