简体   繁体   English

jQuery ui-日期选择器,日期格式

[英]JQuery ui - date picker, Date Formating

I want to impliment the same functionality as in this qeustion JQuery ui - date picker, disabling specific dates , the script working fine(see the code below), but the problem is I am getting Unavailable dates from database, so the dates has a leading zero, ie var unavailableDates = ["90-3-2012", "14-03-2012", "15-03-2012"]; 我想隐含与此qeustion JQuery ui-日期选择器中相同的功能,禁用特定日期 ,脚本可以正常工作(请参见下面的代码),但是问题是我从数据库中获取了不可用日期,因此日期前导零,即var unavailableDates = ["90-3-2012", "14-03-2012", "15-03-2012"]; If I test with same dates without leading zero it works, but I want to with leading zero. 如果我使用相同的日期进行测试而没有前导零,则可以,但是我想使用前导零。

How can we format the dates, I am using the exact code from an answer for the above said quesiton , here is the code 我们如何格式化日期,我使用的是上述问题的答案中的确切代码,这是代码

<script type="text/javascript">
    var unavailableDates = ["9-3-2012", "14-3-2012", "15-3-2012"];

    function unavailable(date) {
        dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
        if ($.inArray(dmy, unavailableDates) == -1) {
            return [true, ""];
        } else {
            return [false, "", "Unavailable"];
        }
    }

    $(function() {
        $("#iDate").datepicker({
            dateFormat: 'dd MM yy',
            beforeShowDay: unavailable
        });

    });
</script>

You can use datepicker to format date like 您可以使用datepicker 格式化日期,例如

 var unavailableDates = ["09-03-2012", "14-03-2012", "15-03-2012", "15-07-2015"]; function unavailable(date) { var dmy = $.datepicker.formatDate('dd-mm-yy', date); console.log(dmy) if ($.inArray(dmy, unavailableDates) == -1) { return [true, ""]; } else { return [false, "", "Unavailable"]; } } $(function() { $("#iDate").datepicker({ dateFormat: 'dd MM yy', beforeShowDay: unavailable }); }); 
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script> <input id="iDate" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM