简体   繁体   中英

jQuery UI datepicker before year 100

I am trying to get datepicker to allow me to pick dates before year 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.

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.

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.

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

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?

If I can get Date() to do it, I should be fine with the jquery ui stuff. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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