package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
-
@author cgao103@fiberhome.com
-
@date 2021-12-30 15:57
*/
public class Test5 {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf1=new SimpleDateFormat(“yyyyMM”);
SimpleDateFormat sdf2=new SimpleDateFormat(“yyyyMMdd”);
Date nowDate=sdf1.parse(“202212”);
Calendar calendar = Calendar.getInstance();
calendar.setTime(nowDate);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
System.out.println(sdf2.format(calendar.getTime()));String year1 = "2020"; String month2 = "12"; int year = calendar.get(Calendar.YEAR); //2015,当前年份 int month = calendar.get(Calendar.MONTH) + 1; //12,当前月,注意加 1
}
相关文章
暂无评论...