Javascript获取Jquery datepicker值并转换为整数以进行计算 [英] Javascript fetch Jquery datepicker value and convert to integer for calculation
问题描述
我遇到以下问题我有2个输入,其ID为"line_start_time"和ID为"line_end_time",并且其中包含datepicker.而且我需要从2个输入中获取值,然后将它们转换为整数,因此我可以使用2个整数进行进一步的计算.
I am having the following problem I have 2 inputs with id 'line_start_time' and id 'line_end_time', and with datepicker in them. And I need to get the values from the 2 inputs, and then convert them into integer, so I can use the 2 integers and do further calculations.
startTime = $("#line_start_time").val()
endTime = $("#line_end_time").val()
我从startTime获得的示例输出是2014年4月2日12:00 AM或2014年4月2日.人们可以教我如何将其转换为整数吗?
An sample output I get for startTime is April 2, 2014 12:00 AM or April 2, 2014. Could people teach me how to convert it into integers please?
非常感谢.
推荐答案
要获取日期信息并将其转换为整数,您可以
For getting the date information and converting them to integers, you could
- 使用
$(".selector").datepicker("getDate");
获取JavaScript Date 实例 - 使用返回的对象的方法获取所需的值.
更多信息:
- 有关JavaScript的 Date 对象的信息,请参见 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date
- 这是 jsFiddle .
- For information about JavaScript's Date object, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
- Here's a jsFiddle.
修改
我刚刚更新了jsFiddle.现在,它以天为单位计算两个选定日期之间的差额.参见 http://jsfiddle.net/martwig/PDu6w/3/.
I've just updated the jsFiddle a bit. Now it calculates the difference between two selected dates in days. See http://jsfiddle.net/martwig/PDu6w/3/.
这篇关于Javascript获取Jquery datepicker值并转换为整数以进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!