时间类型相加

来源:百度知道 编辑:UC知道 时间:2024/06/08 12:34:15
比如说从现在的时间点,加上100天
Date now= new Date();
Date endTime = now+100; //当然,语法错误

谁知道该怎么来做?

GregorianCalendar gc=new GregorianCalendar();
gc.add(GregorianCalendar.DAY_OF_MONTH,100);

你用now.getTime();
返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。为long型的。将得到的数据脚上100天的毫秒数,再将long型转换成时间类型就可以了。
Date now= new Date();
long time = now.getTime();
long time1 = time+(100*24*60*60*1000);
Date after = new Date(time1);
这个after就是100天后的时间