标签:
eclipse下获取系统时间
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package
com.example.timedemo; import
java.text.SimpleDateFormat; import
java.util.Date; import
android.app.Activity; import
android.os.Bundle; import
android.os.Handler; import
android.os.Message; import
android.widget.TextView; public
class
MainActivity extends
Activity { private
TextView time; private
Handler handler = new
Handler() { @Override public
void
handleMessage(Message msg) { time.setText((String)
msg.obj); } }; @Override protected
void
onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); time
= (TextView) findViewById(R.id.text); //
时间显示 new
Thread( new
Runnable() { @Override public
void
run() { //
TODO Auto-generated method stub while
( true )
{ SimpleDateFormat
format = new
SimpleDateFormat( "yyyy年MM月dd日
HH:mm:ss" ); Date
curData = new
Date(System.currentTimeMillis()); //
获取时间 String
str = format.format(curData); Message
msg = new
Message(); msg.obj
= str; handler.sendMessage(msg); } } }).start(); } } |
标签:
原文地址:http://blog.csdn.net/u014311077/article/details/42284721