Item i1=new Item();
int month3=0;
i1.setManufacturingDate(rs.getDate("mfg_date"));
Date date1 = rs.getDate("mfg_date");
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
int month = cal.get(Calendar.MONTH);
int date=cal.get(Calendar.DATE);
int year=cal.get(Calendar.YEAR);
int month2=month+1;
// System.out.print("\t"+month2);
i1.setUseBeforeMonths(rs.getInt("UseBeforeInMonths"));
int month1=rs.getInt("UseBeforeInMonths");
//System.out.print("\t"+month1);
System.out.println("Expiry Date is");
int expiry=month2+month1;
int sum=0;
if(expiry>12)
{
sum=expiry-12;
System.out.println(sum);
month3=sum;
}
else
{
System.out.println(expiry);
month3=expiry;
}
This code calculates the expiry date. But I dont know how to convert it into date format.
I tried this
Calendar c3 = Calendar.getInstance();
c3.set(year, month3, date);
System.out.println(c3);
but it doest not give proper output. Output given by it is
Expiry Date is
1
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=1,WEEK_OF_YEAR=28,WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF_YEAR=191,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=9,HOUR_OF_DAY=21,MINUTE=34,SECOND=39,MILLISECOND=138,ZONE_OFFSET=19800000,DST_OFFSET=0]
Expiry Date is
4
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=4,WEEK_OF_YEAR=28,WEEK_OF_MONTH=2,DAY_OF_MONTH=10,DAY_OF_YEAR=191,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=9,HOUR_OF_DAY=21,MINUTE=34,SECOND=39,MILLISECOND=139,ZONE_OFFSET=19800000,DST_OFFSET=0]
Expiry Date is
11
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=11,WEEK_OF_YEAR=28,WEEK_OF_MONTH=2,DAY_OF_MONTH=28,DAY_OF_YEAR=191,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=9,HOUR_OF_DAY=21,MINUTE=34,SECOND=39,MILLISECOND=139,ZONE_OFFSET=19800000,DST_OFFSET=0]
Please help me to convert date in Date format i.e 'YYYY-MM-DD'. here date variable has date, month3 variable has month and year variable has year
Thank you.