user833129
user833129

Reputation:

How to create a field of format dd/yyyy?

The field is like a DateField but instead its value is just the month and the year like '05/2011' : how to create such a field ?

Upvotes: 0

Views: 85

Answers (1)

Adam Morris
Adam Morris

Reputation: 8545

In java-me, you can use the java.util.Calendar package for formatting the date.

Here is snippet from this tutorial on displaying the date and time in Java ME:

private void outputDateUsingCalendar(Date date) {
   Calendar calendar = Calendar.getInstance();
   calendar.setTime(date);
   StringBuffer sb = new StringBuffer();

   int day = calendar.get(Calendar.DAY_OF_MONTH);
   sb.append(numberToString(day));
   sb.append("-");
   int month = calendar.get(Calendar.MONTH) + 1;
   sb.append(numberToString(month));
   sb.append("-");
   sb.append(calendar.get(Calendar.YEAR));

   StringItem item = new StringItem("Using Calendar", sb.toString());
   mainForm.append(item);
}

Upvotes: 1

Related Questions