javascript jQuery UI - 将 jQuery UI Datepicker 转换为 UNIX 时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11062314/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:59:32  来源:igfitidea点击:

jQuery UI - Convert jQuery UI Datepicker to UNIX time

javascriptjquery-uidatepickerdatetimepickerunix-timestamp

提问by f1nn

I'm using jQuery UI datepicker with time plugin. This is how I display time on the page in datepicker itself:

我正在使用带有时间插件的 jQuery UI datepicker。这就是我在日期选择器本身的页面上显示时间的方式:

21.06.2012 08:00

I'd like to convert this time to UNIX timestamp before sending to backend. How can I do this? I don't need to dispay UNIX time on the page, I only need to convert before posting. I've tried:

我想在发送到后端之前将此时间转换为 UNIX 时间戳。我怎样才能做到这一点?我不需要在页面上显示 UNIX 时间,我只需要在发布前转换。我试过了:

var d = Date.parse(value_of_datepicker);

but had no luck. It seems date should be formated in another way. Also I've tried several build-in datepicker functions, but all of them set date display view. Thanks.

但没有运气。似乎日期应该以另一种方式格式化。我也尝试了几个内置的日期选择器函数,但它们都设置了日期显示视图。谢谢。

回答by Smileek

If you use jQuery timepicker by Trent Richardson, you can do this: $("#your_datepicker").datetimepicker("getDate").getTime() / 1000

如果您使用 Trent Richardson 的 jQuery timepicker,您可以这样做: $("#your_datepicker").datetimepicker("getDate").getTime() / 1000

http://jsfiddle.net/d6Tky/

http://jsfiddle.net/d6Tky/

Remember that this function may return null if no date has been selected.

请记住,如果未选择日期,此函数可能会返回 null。