更改日期格式,与jQuery datepicker中的MySQL格式相同

Raj*_*ani 0 php mysql sql jquery datepicker

我正在使用jQuery日期选择器,问题是日期的格式,我想要的格式与MySQL日期格式相同,因为我没有在MySQL表中获得正确的日期值,因此我在粘贴以下代码。

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#pdate').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate)

});
});
</script>
Run Code Online (Sandbox Code Playgroud)

形成

<input type="text" name="date" title="" placeholder="mm / dd / yyyy" class="date" id="pdate"  required="required"/>
Run Code Online (Sandbox Code Playgroud)

当前,日期选择器的日期格式为,05/16/2014而MySQL的日期格式为MM-DD-YYYY

kri*_*hna 5

像这样

$("#pdate").datepicker({showOn: 'focus',changeMonth: true,
    changeYear: true,dateFormat: 'mm-dd-yy',
    minDate: new Date(currentYear, currentMonth, currentDate)
 });
Run Code Online (Sandbox Code Playgroud)

您需要向dateFormatdatepicker()函数添加属性。

有关更多信息,请检查 here