[J2ME] 如何顯示日期的縮寫?
各位好
小弟是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
08/16 17:11, 1F
→
08/16 17:45, , 2F
08/16 17:45, 2F
推
08/17 00:03, , 3F
08/17 00:03, 3F
→
08/17 00:03, , 4F
08/17 00:03, 4F
→
08/17 00:28, , 5F
08/17 00:28, 5F