0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Java 日付に対応する曜日を取得する

Posted at

int型の年、月、日の情報に紐づく曜日を取得し出力したい

ポイント
Calenderクラスを使用する
月は0~11で設定する

youbiSyutoku.java
Calendar cal = Calendar.getInstance();
int year  = 2016;   // 年
int month = 12 - 1; // 月
int date  = 26;     // 日

cal.set(year, month, date);

// 日付から曜日を取得する
 switch (cal.get(Calendar.DAY_OF_WEEK)) { 
    case Calendar.SUNDAY:     // Calendar.SUNDAY:1 
    	//日曜日
	    System.out.println("日曜日");
	    break;
	case Calendar.MONDAY:     // Calendar.MONDAY:2
	    //月曜日
	    System.out.println("月曜日");
	    break;
	case Calendar.TUESDAY:    // Calendar.TUESDAY:3
	    //火曜日
	    System.out.println("火曜日");
	    break;
	case Calendar.WEDNESDAY:  // Calendar.WEDNESDAY:4
	    //水曜日
	    System.out.println("水曜日");
	    break;
	case Calendar.THURSDAY:   // Calendar.THURSDAY:5
	    //木曜日
	    System.out.println("木曜日");
	    break;
	case Calendar.FRIDAY:     // Calendar.FRIDAY:6
	    //金曜日
	    System.out.println("金曜日");
	    break;
	case Calendar.SATURDAY:   // Calendar.SATURDAY:7
	    //土曜日
	    System.out.println("土曜日");
	    break;
  }
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?