gpt4 book ai didi

javascript - 它在 end_time 中给了我 unsefined(NaN) 那么我该如何解决这个问题

转载 作者:行者123 更新时间:2023-11-27 23:56:58 25 4
gpt4 key购买 nike

如何获得开始时间和结束时间之间的半小时差异

$('#OutletEvents_start_time').datetimepicker({
datepicker:false,
format:'h:i a',
step:30,
onSelectTime: function() {
var time1 = $(this).val().split(':');
var endtime = parseInt(time1[0])+30;
$('#OutletEvents_end_time').val(time1[1]+':'+endtime);
}
});

最佳答案

console.log endtimetime1 变量。确保 time1[0] 可以解析为 int,即返回 NaN 的位置。

您还应该在 parseInt 调用中指定基数:

var endtime = parseInt(time1[0], 10) + 30;

来自MDN :

Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified.

关于javascript - 它在 end_time 中给了我 unsefined(NaN) 那么我该如何解决这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32182054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com