J2ME: Get only year/month/day from DateField
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 dateF开发者_运维技巧ield.
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);
精彩评论