1.直接上代码
//新建日历
Calendar calendar=Calendar.getInstance();
calendar.setTime(fRealityInDate);//进厂日期
String y=String.valueOf( calendar.get(Calendar.YEAR));//年
String m=String.valueOf( calendar.get(Calendar.MONTH)+1);//月分从0开始获取要加1
if ( (calendar.get(Calendar.MONTH)+1)<10) {
m="0"+m;
}
String d=String.valueOf( calendar.get(Calendar.DAY_OF_MONTH));//日
if (calendar.get(Calendar.DAY_OF_MONTH)<10) {
d="0"+d;
}
String w=String.valueOf( calendar.get(Calendar.WEEK_OF_YEAR));//周 第2021年的第20周
if (calendar.get(Calendar.WEEK_OF_YEAR)<10) {
w="0"+w;
}
String t=y+"-"+m+"-"+d;//统计用时间
//获取季
String q=null;
switch (calendar.get(Calendar.MONTH)) {
case Calendar.JANUARY:
case Calendar.FEBRUARY:
case Calendar.MARCH:
q = "01";
break;
case Calendar.APRIL:
case Calendar.MAY:
case Calendar.JUNE:
q = "02";
break;
case Calendar.JULY:
case Calendar.AUGUST:
case Calendar.SEPTEMBER:
q = "03";
break;
case Calendar.OCTOBER:
case Calendar.NOVEMBER:
case Calendar.DECEMBER:
q = "04";
break;
default:
break;
}