作者punding (.)
看板java
标题[J2ME] 如何显示日期的缩写?
时间Sun Aug 16 16:09:43 2009
各位好
小弟是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
1F:→ pico2k:try SimpleDateFormat 08/16 17:11
2F:→ punding:but this is J2ME.. 08/16 17:45
3F:推 PsMonkey:总共也才 12 个,写个 switch 不就.... 08/17 00:03
4F:→ PsMonkey:有时候 kiss 法则还是很重要的.... 08/17 00:03
5F:→ punding:ok,谢谢版大 08/17 00:28