J2ME中使用calendar类获得当前时间

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class DateParser extends MIDlet{        private String[] weekDayArray={"日","一","二","三","四","五","六"};
                public void startApp(){                Calendar calendar=Calendar.getInstance();
                System.out.println(calendar.getTime());
                int year=calendar.get(Calendar.YEAR);
                int month=calendar.get(Calendar.MONTH);
                int day=calendar.get(Calendar.DATE);
                int weekDay=calendar.get((Calendar.DAY_OF_WEEK));
                int am_pm=calendar.get(Calendar.AM_PM);
                int hour=calendar.get(Calendar.HOUR_OF_DAY);
                int minute=calendar.get(Calendar.MINUTE);
                int second=calendar.get(Calendar.SECOND);
                String dateStr=year+"年"+(month+1)+"月"+day+"日"                +" 星期"+weekDayArray[weekDay-1];
                if (am_pm==Calendar.AM){                        dateStr+=" 上午";
                }                else{                        dateStr+=" 下午";
                }                dateStr+=hour+"时"+minute+"分"+second+"秒";
                Alert alert=new Alert("当前时间",dateStr,null,AlertType.ALARM);
                alert.setTimeout(Alert.FOREVER);
                Display.getDisplay(this).setCurrent(alert);
                        }                public void destroyApp(boolean force){                        }                public void pauseApp(){                        }}

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(String,calendar,null,Class,import,j2me)