1. 程式人生 > >後臺初始化日期傳給前端jsp頁面

後臺初始化日期傳給前端jsp頁面

Calendar   cal   =   Calendar.getInstance();   
SimpleDateFormat f1 =new SimpleDateFormat("yyyy");
SimpleDateFormat f2 =new SimpleDateFormat("MM");
SimpleDateFormat f3 =new SimpleDateFormat("dd");
Date date=new Date();
int year=Integer.valueOf(f1.format(date));
int month=Integer.valueOf(f2.format(date));
int day=Integer.valueOf(f3.format(date));
		
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month-1);
cal.set(Calendar.DAY_OF_MONTH, 1);
			
Date startOfMonth = cal.getTime();
			
cal.set(Calendar.DAY_OF_MONTH, day);
Date now =cal.getTime();
			
//給頁面的輸入框賦值
transQuery.setSettleDateFrom(DateUtil.dateToStr(startOfMonth,"yyyy-MM-dd"));
transQuery.setSettleDateTo(DateUtil.dateToStr(now,"yyyy-MM-dd"));