Javascript获取Jquery datepicker值并转换为整数以进行计算 [英] Javascript fetch Jquery datepicker value and convert to integer for calculation

查看:53
本文介绍了Javascript获取Jquery datepicker值并转换为整数以进行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下问题我有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

  1. 使用 $(".selector").datepicker("getDate");
  2. 获取JavaScript Date 实例
  3. 使用返回的对象的方法获取所需的值.

更多信息:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆