java中關於時間的計算

來源:互聯網
上載者:User

標籤:時間   java   

1.描述:在原有時間上增加一個時間差:

    程式碼範例:

      Date psd = sysDate();

      String workTimeP1 = mapP.get("WORK_TIME_") != null ? mapP.get("WORK_TIME_").toString() : "0"; 
      int news=Integer.parseInt(workTimeP1)*60;
      Date ped=DateUtils.addSeconds(psd,news);

2.時間差的計算代碼:以毫秒為例

    public static int secondsBetween(Date smdate,Date bdate) throws Exception  {     
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   //時間格式
        smdate=sdf.parse(sdf.format(smdate));    
        bdate=sdf.parse(sdf.format(bdate));   
        Calendar cal = Calendar.getInstance();     
        cal.setTime(smdate);     
        long time1 = cal.getTimeInMillis();                  
        cal.setTime(bdate);     
        long time2 = cal.getTimeInMillis();          
        long between_seconds=(time2-time1)/(1000);   
             
       return Integer.parseInt(String.valueOf(between_seconds));            
    }  

  Tbpbc35 c35=c35List.get(0);
   c35.setLotStartTime(c36MinDate);//lot開始時間為明細表的最早開始時間
   c35.setLotEndTime(c36MaxDate);//lot結束時間為明細表的最晚結束時間
   int seconds=this.secondsBetween(c35.getLotStartTime(),c35.getLotEndTime());
   int mintues=seconds/60;
   BigDecimal mb=new BigDecimal(mintues);
   c35.setWorkTotalTime(mb);

3.時間的加法:

    int ps = c36.getProdStartDate().getSeconds();//目前時間的華為秒
    int news = ps - betweenDate;//目前時間加
    Date s = c36.getProdStartDate();//目前時間
    s.setSeconds(news);
    c36.setProdStartDate(s);


本文出自 “亙古之焱” 部落格,請務必保留此出處http://610201092.blog.51cto.com/7852003/1653629

java中關於時間的計算

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.