把获取年月日和星期封装成一个方法
private String getDate() {
Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
int w = c.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0) {
w = 0;
}
String mDate = c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH)+1)
+ "月" + c.get(Calendar.DATE) + "日 " + weekDays[w];
return mDate;
}
获取某一天是星期几
private static int getWeekdayOfMonth(int year, int month,int day){
Calendar cal = Calendar.getInstance();
cal.set(year, month-1, day);
dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1;
return dayOfWeek;
}
求三个数中的最小数
private static int minValue(int a, int b, int c) {
if (a < b && a < c) {
return a;
} else if (b < a && b < c) {
return b;
} else {
return c;
}
}
Android开发手动隐藏软键盘
/**
* 手动隐藏软键盘
*/
private void hideKeyboard() {
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(etInputChattingMsg.getWindowToken(), 0);
}