views:

87

answers:

1

I'm trying to use dateField to display which year, month or day has been selected in the calendar. public DateField getDateField() { dateField = new DateField("dateField", DateField.DATE); dateField.setDate(new java.util.Date(System.currentTimeMillis())); }

Then I'd like to use this code, but instead of the long date "Thu Oct 07 00:00:00 GMT+02:00 2010" I would like to just see what month has been selected, like "October" or "10" etc.

String month = dateField.getDate().toString(); System.out.println("Selected month: " + month);

I can't find anything good on this dateField thing... I want to get the short date like "2010-10-05" if that specific date has been selected in the dateField.

+1  A: 
Calendar cal= Calendar.getInstance();
cal.setTime(dateField.getDate());
String date = cal.get(Calendar.YEAR) + "-" + ( cal.get(Calendar.MONTH) + 1 ) + "-" + cal.get(Calendar.DAY_OF_MONTH);
Mahdi Hijazi