求一天内的任何时间至晚上23:59:59秒的剩余时间. 返回类型要int 返回对应的int 使用Date date = new Date(int) 不会出现误差.. 求解. 自己写的有一个 没有计算年份 只计算了时分秒. 返回的时分秒是没问题的. 但set到的地方 使用date转换后在当前的年份上加了12年..
private static int resultTime(SimpleDateFormat simpleDateFormat) throws ParseException {
String lastTime = "23:59:59";
Date date = simpleDateFormat.parse(lastTime);
long result = date.getTime() - new Date().getTime();
return (int) result;
}
求改下.. 谢谢
private static int resultTime(SimpleDateFormat simpleDateFormat) throws ParseException {
String lastTime = "23:59:59";
Date date = simpleDateFormat.parse(lastTime);
long result = date.getTime() - new Date().getTime();
return (int) result;
}
求改下.. 谢谢
这个时间是秒数还是毫秒数?首先,这应该是一个线段返回值为int要求,使用Date date = new Date(int) 不会出现误差..
Date 是一个具体的时间哪一年那一天几时几分几秒几毫秒,是一个点
一个点怎么能和一个线段对应上呢?
new Date(int),这个int是
1970 年 1 月 1 日 00:00:00 GMT
为起点加上int毫秒后这个点的时间
这个时间是秒数还是毫秒数?首先,这应该是一个线段返回值为int要求,使用Date date = new Date(int) 不会出现误差..
Date 是一个具体的时间哪一年那一天几时几分几秒几毫秒,是一个点
一个点怎么能和一个线段对应上呢?
new Date(int),这个int是……
[/Quote]
Date d=null;
try {
d = f.parse("17:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cc=Calendar.getInstance();
cc.set(Calendar.HOUR, d.getHours());
cc.set(Calendar.MINUTE, d.getMinutes());
cc.set(Calendar.SECOND, d.getSeconds());
cc.getTime().getTime();
Calendar c=Calendar.getInstance();
c.set(Calendar.HOUR, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.getTime().getTime(); long l=c.getTime().getTime()-cc.getTime().getTime();
System.out.println(l);
咱俩实现的结果差不多.. 时分秒可以对应上. 但set到cookie后的日期就又不对了. 这个是采用以上函数得到的结果
Thu, 05-May-2022 09:12:31 GMT 想要实现的就是年月日不变. 只计算时间... 求解..