Javascript设置从当前年份到上一年的日期

问题描述:

我想显示从2010年9月1日到当前日期的jquery日历日期.

i want to show jquery calendar dates from 1st september 2010 to current date.

例如

考虑如果我要假脱机报告2011年1月12日,我应该允许选择从2010年9月1日到2011年1月12日的jquery日历.我的问题是如何将日期设置为当前日期为2010年9月1日(如果当前日期为2011年1月11日),即明年.我想从服务器获取日期并在javascript中进行设置.

consider if i am spooling a report on 12th january 2011 ,i should allow jquery calendar selection from 1st september 2010 to 12th janyary 2011 .My question is how to set the date to 1st sep 2010 from current date (if current date is january 11th 2011) i.e next year. I want to get the date from the server and set in the javascript.

目前,我是从服务器端Java这样获得最小日期的

Currently i get the minimum date from serverside java like this

minDate = new Date();                           // timestamp now
Calendar cal = Calendar.getInstance();          // get calendar instance
cal.setTime(minDate);                           // set cal to date
cal.set(2010,cal.SEPTEMBER,1);
minDate = cal.getTime();

输出为20100901

the output would be 20100901

但是我不想在代码中对2010进行硬编码,我希望即使在2011年1月执行时,通用代码也至少要占2010年9月1日.

but i dont want to hardcode 2010 in the code , i want a generic code that takes 1st sep 2010 as minimum even when i execute on january 2011.

使用此:

int year = cal.get(Calendar.YEAR);