如何转换输入类型=“日期"?在时间戳javascript-jquery [英] How convert input type="date" in timestamp javascript-jquery
本文介绍了如何转换输入类型=“日期"?在时间戳javascript-jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要转换一个时间戳,这是我的html代码:
I need to convert a in a timestamp, this is my html code:
<input type="date" name="date_end" id="date_end">
该字段的值我已输入为25/10/2017 我的jquery代码是:
This field has a value that I have put like 25/10/2017 My jquery code is:
var dataEnd = $('[name="date_end"]').val();
if (!dataEnd) {
return false;
} else {
var timestamp_end=$('[name="date_start"]').val().getTime();
console.log("TIMESTAMP END "+timestamp_end);
.....
}
但这是行不通的,任何人都可以帮助我吗?
But this is not work, anyone can help me?
推荐答案
新建一个Date()
,将输入值作为参数传递,然后调用getTime()
.这里是一个例子:
make a new Date()
passing the value of your input as parameter, then call getTime()
. here an example:
$('[name="date_end"]').on('change',function() {
var dataEnd = $(this).val();
console.log((new Date(dataEnd)).getTime());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" name="date_end" id="date_end">
这篇关于如何转换输入类型=“日期"?在时间戳javascript-jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文