Java线程查找系统时间

时间:2013-11-22 06:57:21

标签: java multithreading netbeans time

我用下面的线程来查找系统时间。但这里有一个问题。它始终显示12:11: - PM和秒运行但是在60秒后12:11再没有几分钟的变化秒运行。我的电脑原始时间是12:24 PM ..这里有什么问题。我的坏英国..

public void statTime(){
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                while (true) {                            
                    java.util.Date d = new java.util.Date();
                    SimpleDateFormat sdf = new SimpleDateFormat("hh:MM:ss a");
                    jLabel1.setText(sdf.format(d));
                    Thread.sleep(1000);

                }

            } catch (Exception e) {
            }
        }
    }).start();
}

2 个答案:

答案 0 :(得分:2)

MM是一年中的一年 - 在格式化程序字符串中尝试mm

答案 1 :(得分:0)

使用以下代码

更好地使用系统时间
SimpleDateFormat sdf = new SimpleDateFormat("hh:MM:ss a");
jLabel1.setText(sdf.format(new Date(System.currentTimeMillis())));