码迷,mamicode.com
首页 > 其他好文 > 详细

时间显示

时间:2014-12-31 08:45:43      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

eclipse下获取系统时间

[1].[文件] MainActivity.java ~ 1KB    下载(17) 跳至 [1]

?
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!