我有一个表单和一个按钮加上几分钟到一个时间(hh:MM),但时间是一个span标签。
在Firefox上工作得很好,但是当我在Chrome上测试时,不能使用Date()。 发生了什么?
//Botão adicionar horário agenda. $('.button').click(function() { var $duration_schedule = $('#duration'); var duration = $duration_schedule.val(); // 30 var hour = $('.time_schedule_form').text(); // 10:00 var new_time = self.Plus_minutes(hour, duration); alert(new_time); // 10:30 }); Plus_minutes: function(hour, duration) { var time, new_hour, hours = ''; time = new Date("T"+hour); // Erro at Chrome time.setTime(time.getTime() + duration*60000); hours = time.getHours().toString(); minutes = time.getMinutes().toString(); if (minutes.length > 1) { new_hour = hours + ':' + minutes; } else { new_hour = hours + ':0' + minutes; } return new_hour; },I have a form and one button to plus some minutes to a time(hh:MM), but the time is a span tag.
At Firefox works well, but when I tested at Chrome doesn't work the Date(). What happened?
//Botão adicionar horário agenda. $('.button').click(function() { var $duration_schedule = $('#duration'); var duration = $duration_schedule.val(); // 30 var hour = $('.time_schedule_form').text(); // 10:00 var new_time = self.Plus_minutes(hour, duration); alert(new_time); // 10:30 }); Plus_minutes: function(hour, duration) { var time, new_hour, hours = ''; time = new Date("T"+hour); // Erro at Chrome time.setTime(time.getTime() + duration*60000); hours = time.getHours().toString(); minutes = time.getMinutes().toString(); if (minutes.length > 1) { new_hour = hours + ':' + minutes; } else { new_hour = hours + ':0' + minutes; } return new_hour; },最满意答案
我想这是因为构造函数的输入而发生的! 如果有时间,你应该在几毫秒内输入数字。 数据对象具有以下构造函数:
新的日期(); 新日期(价值); new Date(dateString); 新日期(年,月[,日期[,小时[,分钟[,秒[,毫秒]]]]]);您可以查看Developer.mozilla,然后您可以查看有关格式的更好说明。
也许Firefox正在转换为包含该部分代码中的内容。 我找到了有关数据输入格式的其他解释,你也可以看看: 将字符串转换为日期
I suppose that it is happening because of constructor's input! In case of time you should put numbers in milliseconds. The Data Object have those constructors bellow:
new Date(); new Date(value); new Date(dateString); new Date(year, month[, date[, hours[, minutes[, seconds[,milliseconds]]]]]);you can take at look at Developer.mozilla then you can check a better explanation about formats.
Maybe the Firefox are converting to including something in that part of code. I found out other explanation about Data input formats, you can take a look too at: Convert String to Date
更多推荐
发布评论