private void getWeekAndDay(){
Calendar calendar= Calendar.getInstance();
//获取当前时间为本月的第几周
int week = calendar.get(Calendar.WEEK_OF_MONTH);
//获取当前时间为本周的第几天
int day = calendar.get(Calendar.DAY_OF_WEEK);
if (day==1) {
day=7;
week=week-1;
} else {
day=day-1;
}
System.out.println("今天是本月的第" + week + "周"+",星期"+(day));
}
//获取当前时间(精确到天)且判断季节
private void getCurrentTime() {
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String date = sDateFormat.format(new java.util.Date());
System.out.println("date=" + date);
String dates[] = date.split("-");
System.out.println("dates[0]=" + dates[0]);
System.out.println("dates[1]=" + dates[1]);
System.out.println("dates[2]=" + dates[2]);
System.out.println("---------------------");
System.out.println("dates[0]=" + Integer.valueOf(dates[0]));
System.out.println("dates[1]=" + Integer.valueOf(dates[1]));
System.out.println("dates[2]=" + Integer.valueOf(dates[2]));
int month = Integer.valueOf(dates[1]);
String season = null;
if (month == 12 || month == 1 || month == 2) {
season="冬天";
} else if(month == 3 || month == 4 || month == 5){
season="春天";
} else if(month == 6 || month == 7 || month == 8) {
season="夏天";
}else {
season="秋天";
}
System.out.println("季节:"+season);
}
时间显示的处理
最新推荐文章于 2021-05-18 07:33:20 发布