我正在尝试使用以下代码在我的网站上使用jQuery.calendarPicker:
<script type="text/javascript">
var calendarPicker2 = $("#wedding_date_picker").calendarPicker({
showDayArrows: false,
callback:function(cal) {
console.log(cal.currentDate);
}
});
</script>
我已经设法开始工作,并记录了以下内容:
Date {Wed Aug 21 2013 16:12:19 GMT+0100 (GMT Daylight Time)}
然而,我现在要做的是将此日期并将其格式化为yyyy-mm-dd后将其插入隐藏的输入字段...问题是我不知道该怎么做格式化。
有人可以帮忙吗?谢谢:))
答案 0 :(得分:0)
你可以像这样使用JS函数Date.format
:
var formattedDate = cal.currentDate.format("yyyy-mm-dd");
答案 1 :(得分:0)
//setter
$( ".selector" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
http://jqueryui.com/demos/datepicker/#option-dateFormat
可在此处找到可用日期格式的完整列表: http://docs.jquery.com/UI/Datepicker/formatDate