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