简体   繁体   English

100年之前的jQuery UI datepicker

[英]jQuery UI datepicker before year 100

I am trying to get datepicker to allow me to pick dates before year 100. 我想让日期选择器允许我选择100年之前的日期。

I have found that the shortYearCutoff option needs to be disabled to have this function properly, as it will always change a date ranging from 00-99 to either 1900-99 or 2000-2099. 我发现需要禁用shortYearCutoff选项才能正常使用此功能,因为它将始终将日期从00-99更改为1900-99或2000-2099。

I want to be able to pick between years 1-99 - I would really like to go back years before that, but I think I'm going to create another solution for those dates. 我希望能够在1-99年之间进行选择-我真的很想追溯到几年之前,但是我想我将为这些日期创建另一个解决方案。

Anyway, can anyone think of how this might be done easily, without changing too much? 无论如何,任何人都可以想到在不做太多更改的情况下如何轻松地完成此工作吗?

I found that it seems the javascript Date function changes the 'xx dates to 19xx. 我发现似乎javascript Date函数将'xx日期更改为19xx。

If I can disable that somehow, I should be able to get this working. 如果我可以通过某种方式禁用它,则应该可以使它正常工作。

Here's my current code 这是我当前的代码

        $("#event_date").datepicker({ minDate: new Date(1, 0, 1),changeYear:true,  maxDate: new Date(4000, 11, 31) , yearRange: '1:4000'});
        $("#event_date").datepicker("option", "dateFormat", "yy-mm-dd");

The datepicker shows the proper years in the drop down, but it always defaults to 19xx when I select anything between 0-100 日期选择器在下拉列表中显示正确的年份,但是当我选择0-100之间的任何值时,它始终默认为19xx

I also tested this... 我也测试过了...

        testDate = new Date(12, 11, 11);
        alert(testDate);

This obviously outputs the following: 显然,这将输出以下内容:

Dec 11 1912 00:00:00 GMT-0500 (Eastern Standard Time)

Any idea how to get either of these to automatically default to showing the years between 0 and 100? 知道如何让这两个值自动默认显示0到100之间的年份吗?

If I can get Date() to do it, I should be fine with the jquery ui stuff. 如果我可以让Date()做到这一点,那么我应该可以使用jQuery ui的东西。 I don't need this automatic functionality for dates anywhere in the application I am building. 我不需要在我正在构建的应用程序中的任何日期使用此自动功能。

Thank you kindly for your time. 谢谢您的宝贵时间。

You can write the date as a string in the ISO-8601 ( publication ) format, pass this as the argument to new Date 您可以将日期写成ISO-8601出版物 )格式的字符串,并将其作为参数传递给new Date

new Date('0000-01-01T00:00:00.000Z'); // Sat Jan 01 0 00:00:00 GMT+0000 (GMT Standard Time)
       // YYYY-MM-DD hh:mm:ss

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

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