Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
したがって、このプログラムでは、ユーザーは日付、月、日、年をすべて数字で指定します。ユーザーが「1975」と答えた場合は「75」が必要です。ユーザーが「2004」と答えた場合は「104」が必要です。曜日を計算するには、この数値が必要です。
では、これを行う最善の方法は何でしょうか? それを文字列に変換し、より小さな文字列を作成し、それを int に戻す必要がありますか? もっと簡単な方法はありますか?
単純に、1900 を法とする num を取ることで目的の数を見つけることができます。
必要な曜日が必要な場合は、使用します
Calendar c = Calendar.getInstance(); c.setTime(yourDate); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
これは簡単ではありませんか?