import java.text.ParseException; import java.util.Calendar; public class DateDemo { public static void main(String [] args) throws ParseException { Calendar c = Calendar.getInstance(); int year =c.get(Calendar.YEAR); int month =c.get(Calendar.MONTH)+1; int day =c.get(Calendar.DAY_OF_MONTH); int week =c.get(Calendar.DAY_OF_WEEK); System.out.println(year+"年 ,"+month+"月,"+day+"日,"+"星期"+week); }
}
修改 后
import java.text.ParseException; import java.util.Calendar; public class DateDemo { public static void main(String [] args) throws ParseException { Calendar c = Calendar.getInstance(); int year =c.get(Calendar.YEAR); int month =c.get(Calendar.MONTH)+1; int day =c.get(Calendar.DAY_OF_MONTH); int week =c.get(Calendar.DAY_OF_WEEK); System.out.println(year+"年 ,"+month+"月,"+day+"日,"+getWeek(week)); }
private static String getWeek(int week) { String[] week_form= {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
return week_form[week-1]; }
}