久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

獲得持續(xù)時(shí)間 2 次

Getting duration of 2 times(獲得持續(xù)時(shí)間 2 次)
本文介紹了獲得持續(xù)時(shí)間 2 次的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

如何獲取 YYYYMMDDTHHMMSS 格式的兩個(gè)字符串的持續(xù)時(shí)間?

How can I get the duration of two Strings in the format YYYYMMDDTHHMMSS?

我正在嘗試使用 Calendar 類并檢查 getTimeInMillis().我遇到的問題是它不一致.知道我做錯(cuò)了什么嗎?每次我運(yùn)行這個(gè)程序時(shí),我都會(huì)得到 40-70 行輸出到控制臺,而實(shí)際上應(yīng)該沒有.

I′m trying with using the Calendar class and checking the getTimeInMillis(). Problem I am having with this is that it is not consistent. Any idea what I am doing wrong? Every time I run this program I get 40-70 lines of output to console when it should be none.

public class DurationTester {

    /**
     * Get the duration between two given times
     * @param time1 yyyymmddThhmmss
     * @param time2 yyyymmddThhmmss
     * @return minutes between time1 and time2
     */
    public static int getDuration(String time1, String time2){
        int yyyy1 = Integer.parseInt(time1.substring(0,4));
        int mm1 = Integer.parseInt(time1.substring(4,6));
        int dd1 = Integer.parseInt(time1.substring(6,8));
        int hh1 = Integer.parseInt(time1.substring(9,11));
        int min1 = Integer.parseInt(time1.substring(11,13));

        int yyyy2 = Integer.parseInt(time2.substring(0,4));
        int mm2 = Integer.parseInt(time2.substring(4,6));
        int dd2 = Integer.parseInt(time2.substring(6,8));
        int hh2 = Integer.parseInt(time2.substring(9,11));
        int min2 = Integer.parseInt(time2.substring(11,13));

        Calendar cal1 = Calendar.getInstance();
        cal1.set(yyyy1, mm1, dd1, hh1, min1, 0);
        Calendar cal2 = Calendar.getInstance();
        cal2.set(yyyy2, mm2, dd2, hh2, min2, 0);
        long milliSec = cal1.getTimeInMillis()-cal2.getTimeInMillis();
        long nonNegativeMS = Math.abs(milliSec);
        long seconds = nonNegativeMS / 1000;
        long minutes = seconds / 60;        
        return (int)minutes;
    }

    public static void main(String[] args){
        String t1 = "20130108T150000";
        String t2 = "20130108T131500";

        int errors = 0;
        for(int i=0; i<5000; i++){
            int duration = getDuration(t1,t2);
            if(duration == 104){
                System.out.println("ERROR: Should only be 105 ("+errors++ +")");
            }
        }
    }
}

推薦答案

這是一個(gè)記錄的錯(cuò)誤.

嘗試在設(shè)置之前清除日歷:

Try clearing the calendar before set:

cal1.clear();
cal1.set(yyyy1, mm1, dd1, hh1, min1, 0);

cal2.clear();
cal2.set(yyyy2, mm2, dd2, hh2, min2, 0);

這篇關(guān)于獲得持續(xù)時(shí)間 2 次的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 日韩中文在线视频 | 久久久久久久综合 | 欧美精品综合在线 | 黄视频国产 | 日批日韩在线观看 | 精品美女久久久 | 日韩视频在线播放 | 成人精品一区亚洲午夜久久久 | 精品欧美黑人一区二区三区 | 国产精品视频一区二区三区四区国 | 欧美在线一二三 | 国产精品久久久久久久午夜片 | 看真人视频一级毛片 | 欧美乱人伦视频 | 国产在线区 | 亚洲天堂色 | 久久伊人青青草 | 中文字幕欧美一区 | 国产精品美女久久久 | 欧美精品一区三区 | 欧美一区二区在线 | 欧美xxxx性 | 欧美精品1区2区 | 久久成人免费 | 91精品国产高清一区二区三区 | 九九亚洲 | 免费在线一区二区三区 | 国产一区二区三区在线视频 | 精品免费在线 | 人人擦人人 | 中文字幕一区在线 | 亚洲精品一区在线 | 激情欧美一区二区三区中文字幕 | 久日精品 | h在线| 仙人掌旅馆在线观看 | www久久久| 日本超碰 | 国产精品久久久久久久久久东京 | 成人在线免费观看av | 国产在线观看网站 |