在 jquery 中解析日期选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14774677/
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
Parsing datepicker in jquery
提问by Vlado Pand?i?
In forms I have two inputs for date ,StartDate input and End date input. I also have datepicker implemented ,
在表单中,我有两个日期输入,StartDate 输入和 End date 输入。我也实现了日期选择器,
$("#StartDate").datepicker();
datepicker formats it something like: 02/27/2013 which I don't like but ok.
datepicker 将其格式化为:02/27/2013,我不喜欢,但还可以。
I would like to parse date before putting it in serialized array. Is this good aproach and if it is how can I accoplish this?
我想在将它放入序列化数组之前解析日期。这是一个很好的方法,如果是这样,我怎么能做到这一点?
How to accomplish that End Date inut is bigger than Start That, and not allow the oppsoite file submitting??
如何实现 End Date inut 比 Start That 大,并且不允许 oppsoite 文件提交??
采纳答案by coder
Try this:
尝试这个:
$.datepicker.parseDate('dd/mm/yy', '22/04/2010');
回答by Eli Gassert
Once you set a datepicker, yes it does set the date in plain text, but it also retains the underlying date.
设置日期选择器后,是的,它确实以纯文本形式设置日期,但它也会保留基础日期。
http://api.jqueryui.com/datepicker/#method-getDate
http://api.jqueryui.com/datepicker/#method-getDate
var currentDate = $( ".selector" ).datepicker( "getDate" );
var currentDate = $( ".selector" ).datepicker( "getDate" );
回答by Mario Sannum
You can use dateFormatto set your own format:
您可以使用dateFormat来设置您自己的格式:
$("#StartDate").datepicker({ dateFormat: "yy-mm-dd" });
(Also see the example at jquery ui datepicker.)
(另请参阅jquery ui datepicker 中的示例。)
And as other have stated, you can use the utility function:
正如其他人所说,您可以使用效用函数:
// Extract a date from a string value with a specified format.
$.datepicker.parseDate( format, value, settings )