我一直在尝试计算两个日期之间的时间差,以分钟为单位。下面的代码是我所拥有的。但它给了我负面的价值。谁能帮我!!?
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class time {
/**
* @param args
* @throws ParseException
*/
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
String time1 = "05/01/2010 11:59:00";
String time2 = "04/30/2010 23:59:00";
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy H:mm:ss");
Date date1 = sdf.parse(time1);
Date date2 = sdf.parse(time2);
long difference = date1.getTime() - date2.getTime();
System.out.println(difference/(3600*1000));
}
}