在JAVA中显示每月支持的经过时间 [英] Display elapsed time with month an day support in JAVA

查看:122
本文介绍了在JAVA中显示每月支持的经过时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的申请表中显示经过的时间.
我目前使用以下代码进行此操作:

I need to display elapsed time in my application form.
I currently do this using this code:

    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&月? new SimpleDateFormat("M D HH:mm:ss")无法执行此操作,例如,经过5秒钟时,它也显示1个月零1天!

This Code shows hours,minutes & seconds properly but how can I show DAYS & MONTHS? new SimpleDateFormat("M D HH:mm:ss") can't do this and for example when 5 seconds elapsed it shows 1 month and 1 days too!

我怎么也可以显示月份和日期?

How can I show month and day too?

谢谢

推荐答案

您不应该为它使用Date类,因为日期是时间的瞬间,但是您将其用作持续时间.请仔细阅读 joda时间文档.然后,您可以将PeriodPeriodFormatter用于您的任务.或者,如果您不想使用该库,则可以编写类似的内容.

You should not use the Date class for it, because a date is an instant of time, but you are using it as a duration. Please read carefully joda time documentation about it. And then you could use Period and PeriodFormatter for you task. Or write something similar if you don't want use the library.

这篇关于在JAVA中显示每月支持的经过时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆