Dear All,
I want the year and Month from the following date format.
I am obtaining the DATE from spinner, which is of following format
"
MMM/YYYY" from client side swings.
i want to retrieve the
Month ,
Here is the code
public getMonth(
String monthYearSelected, int weekSelected)
{
this.monthYearSelected = monthYearSelected;
Calendar nederlandCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
try {
System.out.println("Spinner Date :"monthYearSelected);
Date date = format.parse(monthYearSelected);
System.out.println("Parsed Date :" date);
nederlandCal.setTimeInMillis(date.getTime());
System.out.println("Month is:"(nederlandCal.get(Calendar.MONTH)+1));
} catch (ParseException e1) {
e1.printStackTrace();
}
}
output:
Spinner Date :Mon Jun 01 00:00:00 GMT+05:30 2009
Parsed Date :Mon Jun 01 00:00:00 GMT+05:30 2009
Month is:5
But Ideally, I should get 6(For June),
I have a similar kind of issues for
Year too
Calendar nederlandCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
Calendar previous = new GregorianCalendar(TimeZone.getTimeZone("Netherland"));
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
try {
System.out.println("Spinner Date :"+yearSelected);
Date date = format.parse(yearSelected);
System.out.println("Parsed Date :" date);
//nederlandCal.setTime(date);
nederlandCal.setTimeInMillis(date.getTime());
System.out.println("Year is :"+nederlandCal.get(Calendar.YEAR));
} catch (ParseException e1) {
e1.printStackTrace();
}
output:
Spinner Date :Tue Jan 01 00:00:00 GMT+05:30 2008
Parsed Date :Tue Jan 01 00:00:00 GMT+05:30 2008
Year is :2007
But, I should get 2008
I have tried both setTime() and setTimeInMillis(), but none is giving me the proper results
Am i wrong any where....?... Can anybody give me better idea
Kindly help
Regards
Shiva