jQuery.calendarPicker日期格式

jQuery.calendarPicker date format

本文关键字:格式 日期 calendarPicker jQuery      更新时间:2023-09-26

我正试图在我的一个网站上使用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后,将其插入到一个隐藏的输入字段中。。。问题是我不知道如何格式化。

有人能帮忙吗?谢谢:)

您可以像这样使用JS函数Date.format

var formattedDate = cal.currentDate.format("yyyy-mm-dd");

来自jquery UI手册:

//setter
$( ".selector" ).datepicker( "option", "dateFormat", "yy-mm-dd" );

http://jqueryui.com/demos/datepicker/#option-日期格式

可用日期格式的完整列表可在此处找到:http://docs.jquery.com/UI/Datepicker/formatDate