利用線程獲取日期時間時間

package user;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class TimeClock extends Thread {
 UserFaceplane frame;

 public TimeClock(UserFaceplane frame) {
  super();
  this.frame = frame;
 }
@Override
 public void run() {
  while (true)
               {
   GregorianCalendar time = new GregorianCalendar();
   int year = time.get(Calendar.YEAR);
   int month = time.get(Calendar.MONTH)+1;
   int day = time.get(Calendar.DAY_OF_MONTH);
   frame.getLabel7().setText(
     "當前日期:" + year + "." + month + "." + day );
   try {
    Thread.sleep(950);
   } catch (InterruptedException e) {
    e.printStackTrace();
   }

  }
 }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章