我一直在爲一個應用程序的代碼工作,但當我運行代碼時,我無法在模擬器中得到更新的時間。該代碼在編譯器中運行,但不在仿真器中運行。 任何有幫助的建議將不勝感激。計時器是聖誕節倒計時。 這裏是我的代碼:如何在Java模擬器中每秒更新一次?
Calendar today = Calendar.getInstance();
Calendar thatDay = Calendar.getInstance();
thatDay.set(Calendar.DAY_OF_MONTH, 25);
thatDay.set(Calendar.MONTH, 11); // 0-11 so 1 less
thatDay.set(Calendar.YEAR, 2014);
thatDay.set(Calendar.HOUR, 0);
thatDay.set(Calendar.MINUTE, 0);
thatDay.set(Calendar.SECOND, 0);
thatDay.set(Calendar.AM_PM, 0);
System.out.println(thatDay.getTime());
ScheduledExecutorService scheduledExecutorService=
Executors.newScheduledThreadPool(1);
scheduledExecutorService.scheduleAtFixedRate(new ReadThisPeriod(thatDay), 0, 1,
TimeUnit.SECONDS);
long diff = (thatDay.getTimeInMillis() - today.getTimeInMillis())/1000;
long days = diff/(60 * 60 * 24);
long hours = diff/(60 * 60) % 24;
long minutes = diff/60 % 60;
long seconds = diff % 60;
TextView daysBox = (TextView) findViewById(R.id.s1Days);
daysBox.setText(" + "" + days + "" + hours + "" + minutes + " " + seconds + " ");