jQuery 日期选择器中的短日期

Short Date from jQuery Datepicker

我试图从 jQuery 日期选择器中提取一个短日期 ('m/d/yy'),但我一直没有成功。我试过 formatDatedateFormatparseDate,但仍然无法在服务器端获取短日期格式。

我创建了一个 Fiddle,我从这里的其他线程之一提取和修改了它。

据我了解,关于 jQuery UI 日期选择器,我们正在处理两件不同的事情:

  1. 格式化并显示为输入值的日期
  2. 'behind the scenes' 值。我正在尝试 POST 选择的日期 由于日期很短,因此格式 Wed May 13 2015 00:00:00 GMT-0400 (Eastern Daylight Time) 对我不起作用。

我知道可以将日期转换为字符串并以这种方式格式化,但是我不知道在 jQuery UI 库中是否可行。

使用jQuery UI,您可以:

$.datepicker.formatDate('m/d/yy', yourDate);     // where yourDate is the date variable

所以在 jsFiddle 中这将变成:

observable($.datepicker.formatDate('m/d/yy',$el.datepicker("getDate")));

效果见demo(使用datepicker看效果):

> jsFiddle DEMO