转换为int一个拆分字符串

时间:2011-01-10 18:02:59

标签: javascript

伙计们,我知道这听起来很荒谬,但我只是得到了结果MaN ...

tim="09:50"
time = tim.split(":");
minutes = parsefloat

如何获得该值的整数值?

非常感谢!

4 个答案:

答案 0 :(得分:4)

var tim = "9:50";
var time = tim.split(":");
var minutes = parseInt(time[1], 10);

答案 1 :(得分:4)

这应该做你想要的:

var time = "09:50";
var parts = time.split(":");
var hours = parseInt(parts[0], 10);
var minutes = parseInt(parts[1], 10);

答案 2 :(得分:2)

var time = "09:50";
var timeParts = time.split(':');
var hour = parseInt(timeParts[0],10), minute = parseInt(timeParts[1],10);
// you need to specify base because JS tries to make an assumption while parsing.

应该做的伎俩。你处于正确的轨道上,但是parseInt / parseFloat是需要参数的函数。

答案 3 :(得分:1)

var minutes = parseInt(time[1]);
var hours = parseInt(time[0]);