doudouwen2763 2012-01-14 06:26
浏览 36

为什么这段代码显示某些特定输入的奇怪值?

I am developing a typing application using PHP and MySQL and little bit of javascript. The PHP code is used to get the server time. I am using the following javascript function to display the start time and end time(by adding 5 min with the minute value of start time) in the browser.

function display(){   
// get the server time using PHP and print the start time and end time  
var servDateArray='<?php print date("Y/n/d/H/i/s", time())?>'.split('/');  
starttime_year = servDateArray[0];  
starttime_month = servDateArray[1];  
starttime_day = servDateArray[2];  
starttime_hour = servDateArray[3];  
starttime_minutes = servDateArray[4];  
starttime_seconds = servDateArray[5];  

// print the Start time  
document.getElementById("starttime_echoed").innerHTML= starttime_hour+":"+starttime_minutes+":"+starttime_seconds;  
                                                                                                        document.typing.starttime.value=starttime_hour+":"+starttime_minutes+":"+starttime_seconds;  

// print the End time  
endtime_hour = parseInt(starttime_hour) + 0;  
endtime_min = parseInt(starttime_minutes) + 5;  
endtime_sec = parseInt(starttime_seconds) + 0;  

if (endtime_sec>=60) { endtime_sec = -(60 - endtime_sec); endtime_min = parseInt(endtime_min)+1; }  
if (endtime_min>=60) { endtime_min = -(60 - endtime_min); endtime_hour = parseInt(endtime_hour)+1; }  
if (endtime_hour>=24) { endtime_hour = -(24 - endtime_hour); }  
if (endtime_sec<=9) { endtime_sec="0"+endtime_sec; }  
if (endtime_min<=9) { endtime_min="0"+endtime_min; }  
if (endtime_hour<=9) { endtime_hour="0"+endtime_hour; }  
document.getElementById("endtime_echoed").innerHTML= endtime_hour+":"+endtime_min+":"+endtime_sec;  
document.typing.endtime.value=endtime_hour+":"+endtime_min+":"+endtime_sec;  
displayTimer();  
}

The above code works perfectly well for all input values of Hours, minutes and seconds excepts when hour, minute and second are set to either 8 or 9. However, I have tried to debug by inserting a line of code alert(parseInt(starttime_minutes)); after the line endtime_min = parseInt(starttime_minutes) + 5; and it returned 0 when I supplied 8 or 9 as value for minute. I am sure this function returns 0 for hours, minutes and seconds. To be very specific I am giving you am example: If the server time is say 08:09:37 then the end time becomes 00:05:37. I am getting perplexed. Please help.

  • 写回答

2条回答 默认 最新

  • dpd3447 2012-01-14 06:31
    关注

    08 and 09 are not valid numbers, since the 0 prefix indicates that the number is octal, and octal digits only go up to 7. Drop the initial 0.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值