How to create a field of format dd/yyyy?

依然范特西╮ 提交于 2019-12-12 02:03:46

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/6773274/how-to-create-a-field-of-format-dd-yyyy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!