请问怎样获得DateField的年月日呢!散分

BallLei99 2004-11-02 12:29:04
急问
...全文
180 点赞 收藏 14
写回复
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lesliechol 2004-11-18
up
回复
x0y1z2 2004-11-18
哦,上面的
DateField df = null;后面要取得你要的DateField
回复
x0y1z2 2004-11-18
DateField df = null;
Date date = df.getDate();
Calendar c = Calendar.getInstance();
c.setTime(date);
System.out.println(c.get(Calendar.YEAR)+"年"+ (c.get(Calendar.MONTH)+1) +"月");
//Calendar.YEAR的意思自己看文档,还有其他的field
date = c.getTime();
long longTime = date.getTime();
回复
wandou999 2004-11-12
Calendar可以
回复
lesliechol 2004-11-12
请问如果要用Calendar的getTimeInMillis方法将时间变为long,为何不行?
(提示protected无法access)
回复
loverisyour 2004-11-12
大家新手,互相帮助
回复
loverisyour 2004-11-12
转贴给你,定时器,里面就有取时分秒,取年月日一样
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class FixedRateScheduleMIDlet extends MIDlet{
private Timer aTimer;
private ClockTimerTask aTimerTask;
Displayable d;
private Date currentTime;
private Calendar now;
private String nowString="";
public FixedRateScheduleMIDlet() {
}

public void startApp(){
d = new ClockCanvas();
d.addCommand(new Command("Exit",Command.EXIT,1));
d.setCommandListener(new CommandListener(){
public void commandAction(Command c,Displayable s){
notifyDestroyed();}});
currentTime = new Date();
now = Calendar.getInstance();
now.setTime(currentTime);
nowString = now.get(Calendar.HOUR)+"时"+now.get(Calendar.MINUTE)+"分"+now.get(Calendar.SECOND)+"秒";
aTimer = new Timer();
aTimerTask = new ClockTimerTask();
aTimer.scheduleAtFixedRate(aTimerTask,10,1000);
Display.getDisplay(this).setCurrent(d);
}

public void pauseApp(){}

public void destroyApp(boolean unconditional){}

class ClockCanvas extends Canvas{
public void paint(Graphics g){
int width = getWidth();
int height = getHeight();
g.setGrayScale(255);
g.fillRect(0,0,width-1,height-1);
g.setGrayScale(0);
g.drawRect(0,0,width-1,height-1);
g.drawString(nowString,10,10,Graphics.TOP|Graphics.LEFT);
}
}

class ClockTimerTask extends TimerTask{
public final void run(){
currentTime = new Date();
now = Calendar.getInstance();
now.setTime(currentTime);
nowString = now.get(Calendar.HOUR)+"时"+now.get(Calendar.MINUTE)+"分"+now.get(Calendar.SECOND)+"秒";
((ClockCanvas)d).repaint();
}
}

}
回复
marscsdn 2004-11-11
取个日期都要写半天代码!这JAVA到底是什么鬼东西!
回复
flyingghost 2004-11-03
faint,中间少了一句:

cal.setTime(date);

不好意思。^_^
回复
flyingghost 2004-11-03
抛砖。

Calendar cal;
Date date;
cal = Calendar.getInstance();
date = new Date();

g.drawString(new StringBuffer().append(cal.get(Calendar.YEAR)).append("年").append(cal.get(Calendar.MONTH) +1).append("月").append(cal.get(Calendar.DATE)).append("日").toString(), 10, 10, 0);
g.drawString(new StringBuffer().append(cal.get(Calendar.HOUR_OF_DAY)).append(":").append(cal.get(Calendar.MINUTE)).append(":").append(cal.get(Calendar.SECOND)).toString(), 10, 30, 0);
回复
jinsfree 2004-11-02
用Calendar吧
回复
batfree 2004-11-02
在J2ME里用Calendar完全可以的。
回复
BallLei99 2004-11-02
J2me里没有GregorianCalendar吧,我用j2me开发手机应用程序的
回复
icy_csdn 2004-11-02
Date date1 = ....

Calendar calendar = new GregorianCalendar();
calendar.setTime(date1);

int year = calendar.get( Calendar.YEAR );
回复
发动态
发帖子
J2ME
创建于2007-09-28

1.3w+

社区成员

Java J2ME
申请成为版主
社区公告
暂无公告