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;
}
}