The last time we realized the dynamic display of date and time, this time we achieved the display of the school year, semester, week ,:
The first is the display of the school year term:
Calendar c = Calendar. getInstance ();
Int year = c. get (Calendar. YEAR );
Int month = c. get (Calendar. MONTH) + 1; // The month value obtained by the Calendar object is the actual MONTH value minus 1
If (2 <month & month <8)
{
Textview02.setText (year + "--" + (year + 1 ));
Textview03.setText ("second semester ");
}
Else if (month <= 2)
{
Textview02.setText (year-1) + "--" + year );
Textview03.setText ("first semester ");
}
Else
{
Textview02.setText (year + "--" + (year + 1 ));
Textview03.setText ("first semester ");
}
Generally, the year February to the year August is the second semester from the current academic year to the next academic year. At the beginning, I think the remaining months are the first semester from the current year to the next academic year, however, it is found that the month of the current year is January, although it is the first semester, but get (Calendar. YEAR) is the next year, so if (month <= 2), setText (year-1) + "--" + YEAR );
The following is the weekly display: because the value of the week obtained by the Calendar Object is: Sunday is 1, Monday is 2, and so on, so:
Calendar c = Calendar. getInstance ();
Int day = c. get (Calendar. DAY_OF_WEEK );
Switch (day ){
Case 2:
Textview05.setText ("Monday ");
Break;
Case 3:
Textview05.setText ("Tuesday ");
Break;
Case 4:
Textview05.setText ("Wednesday ");
Break;
Case 5:
Textview05.setText ("Thursday ");
Break;
Case 6:
Textview05.setText ("Friday ");
Break;
Case 7:
Textview05.setText ("Saturday ");
Break;
Default:
Textview05.setText ("Sunday ");
Break;
}
The final display effect is:
Because weekly display involves data storage, because we need to first obtain the time value of Monday in the first week of the current school year, and then create a database table and store it in the database, therefore, we do not calculate the number of times per week for the time being.
In addition, because both the school year and the week have to change dynamically, we should also put them in the last Runnable class run () method.
From the tianshuguang Column