public static void main(String[] args)
{
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 = getWeek(c.get(Calendar.DAY OF WEEK));
//System.out.println(year+"年"mouth+"月"day+"日"+week);
int week = c.get(c.get(Calendar.DAY_OF_WEEK));
System.out.println(year+"年"+month+"月"+day+"日"+getWeek(week));
}
//public static int getWeek(int i)
public static String getWeek(int i)
{
String[] weeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
return weeks;
}
把你的int week = c.get(c.get(Calendar.DAY_OF_WEEK)); 改成 int week = c.get(Calendar.DAY_OF_WEEK);
就OK了
import java.util.Calendar;
public class Cal {
/**
* @param args
*/
public static void main(String[] args) {
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(week);
System.out.println(year+"年"+month+"月"+day+"日"+getWeek(week));