Date
专注于为中小企业提供成都做网站、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业海安免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
time
=
request.getParameter("前台传值date");
Date
now
=
new
Date();
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat("yyyy/MM/dd
HH:mm:ss");//获取当前日期
String
nowdate
=
dateFormat.format(
now
);
if(timenowdate){
system.out.println("传值时间早于当前时间");
Date date = new Date();//你具体要赋值的Date值
JComboBox comboBox = new JComboBox();//你自己的下拉列表
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int maxWeek =cal.get(Calendar.WEEK_OF_YEAR);
for(int i=1;i=maxWeek;i++){
comboBox.addItem(i);
}
private void changeDayComboBox(String dyear,String dmouth){
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy/MM");
Calendar rightNow = Calendar.getInstance();
try{
rightNow.setTime(simpleDate.parse(dyear+"/"+dmouth));
}catch(ParseException e){
e.printStackTrace();
}
int days = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);//根据年月 获取月份天数
DefaultComboBoxModel list = new DefaultComboBoxModel();
for(int i = 0; i days; i++){
list.addElement(i+1);
}
m_DayComboBox.setModel(list);
调用
[java] view plain copy
changeDayComboBox("2015","7");
var year=document.getElementById("year").value;
var month=document.getElementById("month").value;
通过Onclick事件获得年和月的值
你是要30天的日期嘛。。。
public String genRqOpts() {
StringBuilder rtn = new StringBuilder("");
java.util.Date date = new java.util.Date();//获得当前系统时间
SimpleDateFormat simple = new SimpleDateFormat("yyyyMMdd");
String time = simple.format(date);
String cur_Y = time.substring(0,4);//年
String cur_M = time.substring(4,6);//月
String cur_D = time.substring(6,8);//日
Calendar calendar = Calendar.getInstance();//初始化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
calendar.set(Integer.parseInt(cur_Y), Integer.parseInt(cur_M), Integer.parseInt(cur_D));
rtn.append("select");
for (int i=0;i30;i++) {//获取页面上下拉选项
calendar.add(Calendar.DATE, -1);
String elRq = sdf.format(calendar.getTime());
rtn.append("option value='");
rtn.append(elRq);
rtn.append("'");
rtn.append(elRq);
rtn.append("/option");
}
rtn.append("/select");
return rtn.toString();
}
DateDropFrame extends JFrame
给year和month添加一个ItemListener来实时计算指定年和月中有多少天就可以了.
代码是用Swing写的,不过看你的图,不像是Swing界面.
/**
* Create the frame.
*/
public DateDropFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
final JComboBox year = new JComboBox();
year.setModel(new DefaultComboBoxModel(getModel(start, end)));
contentPane.add(year);
final JComboBox month = new JComboBox();
month.setModel(new DefaultComboBoxModel(getModel(1, 12)));
contentPane.add(month);
final JComboBox day = new JComboBox();
contentPane.add(day);
year.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
setDay(year, month, day);
}
});
month.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
setDay(year, month, day);
}
});
setDay(year, month, day);
setContentPane(contentPane);
}
/**
* calculate days in select month year
*/
private void setDay(JComboBox year, JComboBox month, JComboBox day) {
int y = Integer.parseInt((String) year.getSelectedItem());
int m = Integer.parseInt((String) month.getSelectedItem());
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, y);
c.set(Calendar.MONTH, m - 1);
int days = c.getActualMaximum(Calendar.DAY_OF_MONTH);
day.setModel(new DefaultComboBoxModel(getModel(1, days)));
}
/**
* get String array [start, end]
*/
private String[] getModel(int start, int end) {
String[] m = new String[end - start + 1];
for (int i = 0; i m.length; i++) {
m[i] = String.valueOf(i + start);
}
return m;
}