[J2ME] 如何顯示日期的縮寫?

看板java作者 (.)時間16年前 (2009/08/16 16:09), 編輯推噓1(104)
留言5則, 3人參與, 最新討論串1/1
各位好 小弟是Java新手 在寫顯示目前時間的時候遇到了一點問題 就是想讓月份以英文縮寫的方式呈現(Aug,May...etc) 不過因為都是回傳int,也不知道該如何使用其他的API讓他變成英文(黃色那行) 而且回傳的int也不一定代表是該月份的數字 除了使用字串陣列之外,還有什麼方式可以解決這個問題的呢? 程式碼如下 import java.util.Calendar; import java.util.Date; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.DateField; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.*; public class Contacts extends MIDlet implements Runnable { private Display display = Display.getDisplay(this); private Form newForm = new Form("Contacts"); private Date date; private DateField currentTime = new DateField("", DateField.DATE_TIME); private Calendar calendar = Calendar.getInstance(); private String time; public Command newCommand(String description) { Command button = new Command(description, Command.OK, 1); return button; } public void startApp() { newForm.append("Current Time:"); new Thread(this).start(); } public void run() { try { while (true) { Thread.sleep(100); newForm.deleteAll(); date = new Date(); currentTime.setDate(date); calendar.setTime(date); time = calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND) + "," + calendar.get(Calendar.YEAR) + "," + calendar.get(Calendar.MONTH) + "," + calendar.get(Calendar.DATE); newForm.append(currentTime); newForm.append(time + "\n"); display.setCurrent(newForm); } } catch (InterruptedException ex) { ex.printStackTrace(); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } -- ╓───────────────╖ ████████████████▁▁▁▁▁▁▁▁▁ ███████████████ http://0rz.tw/5c1C0 ████ █████████ ███來自punding的筆跡 ████▔▔▔▔▔▔▔▔▔ ───────────────┘ ▔▔▔▔▔▔▔▔▔▔ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.105.116.17

08/16 17:11, , 1F
try SimpleDateFormat
08/16 17:11, 1F

08/16 17:45, , 2F
but this is J2ME..
08/16 17:45, 2F

08/17 00:03, , 3F
總共也才 12 個,寫個 switch 不就....
08/17 00:03, 3F

08/17 00:03, , 4F
有時候 kiss 法則還是很重要的....
08/17 00:03, 4F

08/17 00:28, , 5F
ok,謝謝版大
08/17 00:28, 5F
文章代碼(AID): #1AXxxBf1 (java)