【问题标题】:How can i get the day in the datepicker javascript?我如何在 datepicker javascript 中获取日期?
【发布时间】:2019-05-14 09:24:23
【问题描述】:

这是我从一些网站获得的 javascript 代码。但它只是给了我像 (01-06-2019/01-07-2019/01-08-2019) 这样的日期月份和年份,我想输出正确的日期。

我可以在这里改变什么?

<script type="text/javascript">
    $("#monthPicker").datepicker({
        dateFormat: 'MM yy',
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,

        onClose: function (dateText, inst) {
            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();

            $(this).val($.datepicker.formatDate('MM yy', new Date(year, month, 1)));
            //$(this).datepicker('setDate', new Date(year, month, 1));
            $(this).datepicker('refresh');
        }
    });

    $("#monthPicker").focus(function () {
        $(".ui-datepicker-calendar").show();
        $("#ui-datepicker-div").position({
            my: "center top",
            at: "center bottom",
            of: $(this)
        });
    });


</script>

【问题讨论】:

  • 你想以哪种格式显示日期?
  • @MannanBahelim 日月年

标签: asp.net-mvc datepicker


【解决方案1】:
 $("#monthPicker").datepicker({
        todayHighlight: true,
        format: 'dd-M-yyyy',
        endDate: '+0d',
        setDate: new Date(),
        autoclose: true
    });

用日期格式装饰你的文本框。

@Html.TextBoxFor(model => model.Date, "{0:dd-MMM-yyyy}", new { @class = "form-control", @maxlength = "11", @readonly = true })

如需更多自定义格式,请访问: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多