Javascript设置从当前年份到上一年的日期 [英] Javascript setting Date to previous year from the current year

查看:96
本文介绍了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);

这篇关于Javascript设置从当前年份到上一年的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆