2012-06-13 45 views

回答

3
String mydate = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime()); 
+0

这是答案的一半 – Lucifer

0

将其复制到您的班级中。

private RefreshHandler mRedrawHandler = new RefreshHandler(); 

class RefreshHandler extends Handler { 
@Override 
public void handleMessage(Message msg) { 
String curDateTime = DateFormat.getDateInstance().format(Calendar.getInstance().getTime()); 
((TextView)findViewById(R.id.textView1)).setText(curDateTime); 
sleep(60000); } 

public void sleep(long delayMillis) { 
this.removeMessages(0); 
sendMessageDelayed(obtainMessage(0), delayMillis); 
    } 
} 

如果是的onCreate,调用mRedrawHandler.sleep(延迟);

1

通过使用

String mydate =  java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime()); 

得到的日期,你可以设置这个值在TextView中使用,

TextView textView= (TextView)findViewById(R.id.textViewName); 
textView.setText(mydate); 
+0

使用处理程序,timertask来更新每分钟 –

相关问题