public class getcurrentdate { public int years = 2002; public int months = 12; public int days = 31; public int weeks = 52; date mydate = new date(); simpledateformat formatter = new simpledateformat("yyyy-mm-dd w");
/*获得年的下拉列表*/ public string getcurrentyear() { string content = ""; for (int i = integer.parseint(formatter.format(mydate).tostring().substring(0, 4)); i >= years; i--) { content += "<option value='" + i + "'>" + i + "年</option>/n";
} return content; }
/*获得月的下拉列表*/ public string getcurrentmonth() { string m; string content = "";
for (int i = 1; i <= months; i++) { m=i<10?("0" + i):integer.tostring(i); if(i == integer.parseint(formatter.format(mydate).tostring().substring(5, 7))) content += "<option value='" + m + "' selected>" + m + "月</option>/n"; else content += "<option value='" + m + "'>" + m + "月</option>/n"; } return content; }
/*获得日的下拉列表*/ public string getcurrentday() { string content = ""; string m;
for (int i = 1; i <= days; i++){ m=i<10?("0" + i):integer.tostring(i); if(i == integer.parseint(formatter.format(mydate).tostring().substring(8, 10))) content += "<option value='" + m + "' selected>" + m + "日</option>/n"; else content += "<option value='" + m + "'>" + m + "日</option>/n"; } return content; }
/*获得周的下拉列表*/ public string getcurrentweek() { string content = ""; string m;
for (int i = 1; i <= weeks; i++){ m=i<10?("0" + i):integer.tostring(i); if(i == integer.parseint(formatter.format(mydate).tostring().substring(11))) content += "<option value='" + m + "' selected>" + m + "周</option>/n"; else content += "<option value='" + m + "'>" + m + "周</option>/n"; } return content; } }