建设创意网站,做磨毛布内销哪个网站比较好,哪个网站做母婴用品好,哪有做网站一、简介有个需求是#xff0c;累加通话时长#xff0c;把上次通话时长加上本次通话时长#xff0c;依次累加。二、实现Testpublic void TestA() throws ParseException {SimpleDateFormat myFormatter new SimpleDateFormat(HH:mm:ss);SimpleDateFormat forma…一、简介有个需求是累加通话时长把上次通话时长加上本次通话时长依次累加。二、实现Testpublic void TestA() throws ParseException {SimpleDateFormat myFormatter new SimpleDateFormat(HH:mm:ss);SimpleDateFormat format new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);//上一次通话时长HealthConsultation healthConsultation new HealthConsultation();healthConsultation.setConsultinghours(00:00:08);//呼叫时长 3HealthCallStateRecord healthCallStateRecorda new HealthCallStateRecord();healthCallStateRecorda.setCreatedate(format.parse(2017-12-19 17:43:42));//本次通话时长 4HealthCallStateRecord healthCallStateRecordb new HealthCallStateRecord();healthCallStateRecordb.setCreatedate(format.parse(2017-12-19 18:51:50));//4-3的时间 获得两个时间的毫秒时间差异long diff healthCallStateRecordb.getCreatedate().getTime() - healthCallStateRecorda.getCreatedate().getTime();//这样得到的差值是微秒级别long nd 1000 * 24 * 60 * 60;long nh 1000 * 60 * 60;long nm 1000 * 60;long ns 1000;// 计算差多少天long day diff / nd;// 计算差多少小时long hour diff % nd / nh;// 计算差多少分钟long min diff % nd % nh / nm;// 计算差多少秒//输出结果long sec diff % nd % nh % nm / ns;//判断上次是否有通话如果有通话时长就都累加if(healthConsultation.getConsultinghours() ! null){Calendar cal Calendar.getInstance();cal.setTime(myFormatter.parse(healthConsultation.getConsultinghours()));int shi (int)cal.get(Calendar.HOUR_OF_DAY)(int)hour;int fendo (int)cal.get(Calendar.MINUTE)(int)min;int miao (int)cal.get(Calendar.SECOND)(int)sec;//秒大于60设为00,然后判断分是否大于60分钟,如果是则分钟清0,小时加1,否则分钟加1。if(miao60){miao00;if(fendo60){fendo 00;shi shi1;}else {fendo fendo 1;}}Date dates myFormatter.parse(shi : fendo : miao);System.out.println(不为空当前时间 : myFormatter.format(dates));}else {//如果上次无通话就把本次时长设为通话时长。Date dates myFormatter.parse(hour : min : sec);System.out.println(为空当前时间 : myFormatter.format(dates));}}输出结果为:不为空当前时间 : 01:08:16通话时长为1个多小时。