1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package getDayName;
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date;
public class GetDayName { public String getDayName(int a, int b) throws Exception { String answer = ""; String[] week = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; String sour = "2016"; if(a < 10 && b < 10) { sour += "0"+a+""+"0"+b; }else if (a < 10){ sour += "0"+a+""+b; }else if (b < 10) { sour += a+""+"0"+b; }else { sour += a+""+b; } System.out.println(sour); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); Date date = format.parse(sour); Calendar cal = Calendar.getInstance(); cal.setTime(date); int num = cal.get(Calendar.DAY_OF_WEEK)-1; answer = week[num]; return answer; } public static void main(String[] args) throws Exception { GetDayName gdn = new GetDayName(); int a = 1, b = 1; System.out.println(gdn.getDayName(a,b)); } }
|