【发布时间】:2011-10-18 12:21:54
【问题描述】:
我需要在申请表中显示经过的时间。
我目前使用以下代码执行此操作:
AppTimer = new Timer();
AppTimer.scheduleAtFixedRate(new java.util.TimerTask() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
public void run() {
sdf.setTimeZone(java.util.TimeZone.getTimeZone("GMT+0"));
lblAppRunTime.setText(""+sdf.format(new Date(AppTimeCounter*1000)));
AppTimeCounter++;
}
},1000, 1000);
此代码正确显示小时、分钟和秒,但我如何显示 DAYS 和 MONTHS?
new SimpleDateFormat("M D HH:mm:ss") 不能这样做,例如当 5 秒过去时,它也显示 1 个月零 1 天!
如何也显示月份和日期?
谢谢
【问题讨论】:
标签: java timer simpledateformat elapsedtime