为什么日期时间选择器给出月份名称而不是数字?

发布于 2025-01-04 20:09:55 字数 504 浏览 2 评论 0原文

我正在尝试在我的应用程序中使用 DateTimePicker。 我在 View/Shared/EditorTemplates 文件夹下创建 Date.cshtml 它包含这样的内容:

@model System.DateTime

@Html.TextBox("", Model.ToString("dd-MM-yyyy"),
new {@class = "tanggal", @maxlength = "10"})

然后我在脚本文件夹下创建 EditorHookup.js 文件,其内容如下:

$(document).ready(function () {
    $('.tanggal').datepicker({
        dateFormat: 'dd-MM-yyyy'
    });
});

我希望得到的结果是这样的: 01-01-2012 但结果是: 01-January-20122012

我应该做什么来解决这个问题?

I'm trying to use DateTimePicker in my application.
I create Date.cshtml under the View/Shared/EditorTemplates folder
and it consist something like this:

@model System.DateTime

@Html.TextBox("", Model.ToString("dd-MM-yyyy"),
new {@class = "tanggal", @maxlength = "10"})

then I create EditorHookup.js file under the script folder with the content like this:

$(document).ready(function () {
    $('.tanggal').datepicker({
        dateFormat: 'dd-MM-yyyy'
    });
});

I expect to get the result to be like this: 01-01-2012
but the result is: 01-January-20122012

What should I do to fix that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨落画卷 2025-01-11 20:09:55

使用 mm 表示月份,而不是 MM。请参阅此处: http://docs.jquery.com/UI/Datepicker/formatDate

例如:

dateFormat: 'dd-mm-yy'     //notice the year format also has been changed, per Izkata's comment

Use mm for month instead of MM. See here: http://docs.jquery.com/UI/Datepicker/formatDate

E.g.:

dateFormat: 'dd-mm-yy'     //notice the year format also has been changed, per Izkata's comment
硪扪都還晓 2025-01-11 20:09:55

仔细检查日期选择器的文档,特别是有关月份的代码。我猜你想要类似 mm 而不是 MM 的东西。

Double-check the documentation for your datepicker, specifically regarding the code for month. I'd guess that you want something like mm instead of MM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文