2 sinat 18607755 sinat_18607755 于 2014.08.21 12:10 提问

计算两个时间相差的天数,小时数,分钟数,秒数 中出现的对象问题

import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Homework4 {
void display(String begin,String end){
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date begin1 = sim.parse(begin);
Date end1 = sim.parse(end);
} catch (ParseException e) {
e.printStackTrace();
}
long between = (end1.getTime() - begin1.getTime())/1000;
long days = between/(24*3600);
long hours = between%(24*3600)/3600;
long minutes = between%3600/60;
long seconds = between%60/60;
System.out.println("天:" + days + "小时:" + hours + "分钟:" + minutes + "秒:"+ seconds);
}
加粗部分的end1 和begin1报错为
Multiple markers at this line
- end1 cannot be resolved
- begin1 cannot be resolved

1个回答

xiaoxiao_shenle
xiaoxiao_shenle   2014.08.21 22:00

Date begin1 = null;
Date end1 = null;
try {
begin1 = sim.parse(begin);
end1 = sim.parse(end);
} catch (ParseException e) {
e.printStackTrace();
}
long between = (end1.getTime() - begin1.getTime())/1000;

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!