javascript 通过 jQuery datepicker 将日期转换为 unix 时间戳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14335048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert date to unix timestamp through jQuery datepicker
提问by bicycle
I want to check whether the entered dob is above 18th old. For that i want to convert to convert the entered date to the unix time stamp. I tried using:
我想检查输入的dob是否超过18岁。为此,我想将输入的日期转换为 unix 时间戳。我尝试使用:
$.datepicker.formatDate('@', $('#dob').val());
But it gives three additional zeros and also goes one day earlier. Like for "10/10/1967" it returns: -70369200000 while it should return: -70329600. How should i change it?
但它给出了三个额外的零并且也提前了一天。就像“10/10/1967”一样,它返回:-70369200000,而它应该返回:-70329600。我应该怎么改?
回答by Alnitak
To get the Unix time out of a date picker use:
要从日期选择器中获取 Unix 时间,请使用:
$(el).datepicker('getDate') / 1000;
However you should also note that the semantics of Date
objects are not well defined for "negative" dates.
但是,您还应该注意,Date
对象的语义没有为“负”日期很好地定义。