java技术博客

jsp博客
数据加载中……
FormateDateOutput.java
/*
*日历按照格式输出
*/
import java.util.Calendar;
import java.swing.JOptionPane;
import java.text.SimpleDateFormat;
public class FormatDateOutput{
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.getActualMaxmum(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;}}

posted on 2008-10-20 13:24 郭兴华 阅读(79) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: