开发者

How to create a field of format dd/yyyy?

The field is like a DateField but instead its value is just t开发者_C百科he month and the year like '05/2011' : how to create such a field ?


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜