第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

尋找Java格式的時間實(shí)用程序

尋找Java格式的時間實(shí)用程序

ABOUTYOU 2023-09-06 14:53:33
我正在尋找一個用于 java 的時間實(shí)用程序,我可以在其中給出以秒或以毫為單位的時間,并且它會以方法返回,例如,getSeconds因此getMinutes我可以輕松地將文本格式化為看起來像Remaining 1 day 2 hours 3 minutes and 4 seconds. 有誰知道嗎?
查看完整描述

1 回答

?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個贊

一分鐘有 60 秒,一小時有 60 分鐘,一天有 24 小時,所以:


private static final int SECONDS_IN_MINUTE = 60;

private static final int SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;

private static final int SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR;

然后你只需要繼續(xù)劃分:


class RemainingTime {

    private static final int SECONDS_IN_MINUTE = 60;

    private static final int SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;

    private static final int SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR;


    private int totalSeconds, days, hours, minutes, seconds;


    public RemainingTime(int totalSeconds) {

        this.totalSeconds = totalSeconds;

        init();

    }


    private void init() {

        int remainingSeconds = totalSeconds;

        days = remainingSeconds / SECONDS_IN_DAY;


        remainingSeconds -= days * SECONDS_IN_DAY;

        hours = remainingSeconds / SECONDS_IN_HOUR;


        remainingSeconds -= hours * SECONDS_IN_HOUR;

        minutes = remainingSeconds / SECONDS_IN_MINUTE;


        remainingSeconds -= minutes * SECONDS_IN_MINUTE;

        seconds = remainingSeconds;

    }


    public int getDays() { return days; }

    public int getHours() { return hours; }

    public int getMinutes() { return minutes; }

    public int getSeconds() { return seconds; }

}

你像這樣使用它:


RemainingTime rt = new RemainingTime(274119);


System.out.println(String.format(

        "Remaining %s day(s), %s hour(s), %s minute(s) and %s second(s)",

        rt.getDays(), rt.getHours(), rt.getMinutes(), rt.getSeconds()));

輸出:


Remaining 3 day(s), 4 hour(s), 8 minute(s) and 39 second(s)


查看完整回答
反對 回復(fù) 2023-09-06
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號