import java.util.Calendar;
import javax.swing.JOptionPane;
import java.text.SimpleDateFormat;
public class FormateDateOutput
{
private int year;
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("请输入有效的年份(YYYY):");
int year1 = Integer.parseInt(input);//将字符串转化为整数
FormateDateOutput out = new FormateDateOutput();
out.setYear(year1);
if(year1 != 0 && input.length() == 4)
{
out.FormateDateStr();
}
else
{
System.out.println("输入的年份无效。");
}
System.exit(0);
}
public void FormateDateStr()
{
SimpleDateFormat formatter = (SimpleDateFormat)SimpleDateFormat.getDateInstance();
formatter.applyPattern("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
for(int i = 0; i <12; i++ )
{
cal.set(year, i,1);
int temp = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int j = 1; j <= temp; j++)
{
cal.set(year, i, j);
String str = formatter.format(cal.getTime());
System.out.println("当前的时间是:" + str);
}
}
}
public void setYear(int year)
{
this.year = year;
System.out.println("the year is " + this.year);
}
public int getYear()
{
return year;
}
}
问题1:这句话是声明formatter=SimpleDateFormat.getDateInstance();的返回值,加(SimpleDateFormat)是什么意思?
2:cal只是一个Calendar类型变量,没有和Calendar类型对象进行关联,怎么能调用那几个方法呢?
晕了
神!!!救救我